Skip to content

Commit 08849a5

Browse files
committed
wombat: better detection of top replay frame when in 'non-frame container' mode
avoids banner being accidentally added to inner frames!
1 parent 22dc59f commit 08849a5

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pywb/static/wb.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ this.load = function() {
136136

137137
window._wb_js_inited = true;
138138

139+
// Non-Framed Replay OR top frame for framed replay!
139140
if (window.wbinfo && (!window.__WB_top_frame || window.__WB_top_frame == window)) {
140141
if (wbinfo.is_framed && wbinfo.mod != "bn_") {
141142
var hash = window.location.hash;
@@ -154,6 +155,7 @@ this.load = function() {
154155
// Init Banner (no frame or top frame)
155156
add_event("readystatechange", init_banner, document);
156157

158+
// Framed Replay
157159
} else if (window.__WB_top_frame && window != window.__WB_top_frame && window.__WB_top_frame.update_wb_url) {
158160
add_event("readystatechange", notify_top, document);
159161
}

pywb/static/wombat.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,25 +2111,36 @@ var wombat_internal = function($wbwindow) {
21112111
}
21122112

21132113
function init_top_frame($wbwindow) {
2114-
function check_frame(win, frame) {
2114+
function next_parent(win) {
21152115
try {
2116-
return (win && win.wbinfo && (!win.wbinfo.is_frame == !frame));
2116+
if (!win) {
2117+
return false;
2118+
}
2119+
2120+
// if no wbinfo, see if _wb_wombat was set (eg. if about:blank page)
2121+
if (!win.wbinfo) {
2122+
return (win._wb_wombat != undefined);
2123+
} else {
2124+
// otherwise, ensure that it is not a top container frame
2125+
return !win.wbinfo.is_frame;
2126+
}
2127+
21172128
} catch (e) {
21182129
return false;
21192130
}
21202131
}
2121-
2132+
21222133
var replay_top = $wbwindow;
21232134

2124-
while ((replay_top.parent != replay_top) && check_frame(replay_top.parent, false)) {
2135+
while ((replay_top.parent != replay_top) && next_parent(replay_top.parent)) {
21252136
replay_top = replay_top.parent;
21262137
}
21272138

21282139
$wbwindow.__WB_replay_top = replay_top;
21292140

21302141
var real_parent = replay_top.__WB_orig_parent || replay_top.parent;
21312142

2132-
if (real_parent != $wbwindow && check_frame(real_parent, true)) {
2143+
if (real_parent != $wbwindow && real_parent && real_parent.wbinfo && real_parent.wbinfo.is_frame) {
21332144
$wbwindow.__WB_top_frame = real_parent;
21342145

21352146
// Disable frameElement also as this should be top frame

0 commit comments

Comments
 (0)