Skip to content

Commit e006bcd

Browse files
committed
wombat: ensure wombat restored if document.open() or document.write() wipe it (eg. in FF)
use orig_getAttribute when checking iframe.src is not blank
1 parent 69f8382 commit e006bcd

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

pywb/static/wombat.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,15 +1607,36 @@ var wombat_internal = function($wbwindow) {
16071607
return;
16081608
}
16091609

1610+
var check_wombat = function(win) {
1611+
if (win && !win._wb_wombat) {
1612+
win._WBWombat = wombat_internal(win);
1613+
win._wb_wombat = new win._WBWombat(wb_info);
1614+
console.log("Reinit Wombat");
1615+
}
1616+
}
1617+
1618+
// Write
16101619
var orig_doc_write = $wbwindow.document.write;
16111620

16121621
var new_write = function(string) {
16131622
new_buff = rewrite_html(string);
16141623
orig_doc_write.call(this, new_buff);
1624+
check_wombat(this.defaultView);
16151625
}
16161626

16171627
$wbwindow.document.write = new_write;
16181628
$wbwindow.Document.prototype.write = new_write;
1629+
1630+
// Open
1631+
var orig_doc_open = $wbwindow.document.open;
1632+
1633+
var new_open = function() {
1634+
orig_doc_open.call(this);
1635+
check_wombat(this.defaultView);
1636+
}
1637+
1638+
$wbwindow.document.write = new_open;
1639+
$wbwindow.Document.prototype.write = new_open;
16191640
}
16201641

16211642
//============================================
@@ -1636,11 +1657,16 @@ var wombat_internal = function($wbwindow) {
16361657
win = iframe.contentWindow;
16371658
}
16381659

1639-
if (!win || win == $wbwindow || win._skip_wombat || win._wb_wombat) {
1640-
return iframe;
1660+
try {
1661+
if (!win || win == $wbwindow || win._skip_wombat || win._wb_wombat) {
1662+
return iframe;
1663+
}
1664+
} catch (e) {
1665+
console.log(e);
16411666
}
16421667

1643-
var src = iframe.src;
1668+
//var src = iframe.src;
1669+
var src = orig_getAttribute.call(this, "src");
16441670

16451671
if (!src || src == "" || src == "about:blank" || src.indexOf("javascript:") >= 0) {
16461672
win._WBWombat = wombat_internal(win);

0 commit comments

Comments
 (0)