From 9f81933fbd511df0af918f247cdcaca43ebb6924 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Thu, 4 Oct 2018 17:29:18 -0400 Subject: [PATCH] wombat reinit fix (#383) * wombat init fix: - fix change from #339 which removed reiniting of wombat - allow reiniting of wombat if inited via init_new_window_wombat() - don't allow if reinited directly from , as happened in document import * tests: fix tests for 'new _WBWombat -> WombatInit' change * wombat: window.frames optimization: - since window.frames === window, no need for separate override! - ensure init_new_window_wombat() is called on any returned window from object proxy --- pywb/static/wombat.js | 19 +++++++++++++++++++ pywb/static/wombatProxyMode.js | 11 +++++++++++ pywb/templates/head_insert.html | 6 ++---- tests/test_integration.py | 2 +- tests/test_memento.py | 2 +- tests/test_prefixed_deploy.py | 2 +- tests/test_redirect_classic.py | 2 +- tests/test_root_coll.py | 4 ++-- 8 files changed, 38 insertions(+), 10 deletions(-) diff --git a/pywb/static/wombat.js b/pywb/static/wombat.js index 4b0ba4b4..47011555 100644 --- a/pywb/static/wombat.js +++ b/pywb/static/wombat.js @@ -2253,6 +2253,12 @@ var _WBWombat = function($wbwindow, wbinfo) { //============================================ function override_frames_access($wbwindow) { + // If $wbwindow.frames is the window itself, nothing to override + // This can be handled in the Obj Proxy + if ($wbwindow.Proxy && $wbwindow === $wbwindow.frames) { + return; + } + $wbwindow.__wb_frames = $wbwindow.frames; var getter = function() { @@ -3543,6 +3549,9 @@ var _WBWombat = function($wbwindow, wbinfo) { } } } else if (type === "object" && retVal && retVal._WB_wombat_obj_proxy) { + if (retVal instanceof Window) { + init_new_window_wombat(retVal); + } return retVal._WB_wombat_obj_proxy; } @@ -4091,3 +4100,13 @@ var _WBWombat = function($wbwindow, wbinfo) { window._WBWombat = _WBWombat; +window._WBWombatInit = function() { + if (!this._wb_wombat || !this._wb_wombat.actual) { + this._wb_wombat = new _WBWombat(this, wbinfo); + this._wb_wombat.actual = true; + } else if (!this._wb_wombat) { + console.warn("_wb_wombat missing!"); + } +} + + diff --git a/pywb/static/wombatProxyMode.js b/pywb/static/wombatProxyMode.js index e5dc6086..c49b9c44 100644 --- a/pywb/static/wombatProxyMode.js +++ b/pywb/static/wombatProxyMode.js @@ -374,3 +374,14 @@ var _WBWombat = function ($wbwindow, wbinfo) { window._WBWombat = _WBWombat; +window._WBWombatInit = function() { + if (!this._wb_wombat || !this._wb_wombat.actual) { + this._wb_wombat = new _WBWombat(this, wbinfo); + this._wb_wombat.actual = true; + } else if (!this._wb_wombat) { + console.warn("_wb_wombat missing!"); + } +} + + + diff --git a/pywb/templates/head_insert.html b/pywb/templates/head_insert.html index f6b42e3c..dbf89ca2 100644 --- a/pywb/templates/head_insert.html +++ b/pywb/templates/head_insert.html @@ -44,10 +44,8 @@ wbinfo.wombat_opts = {}; - if (window && window._WBWombat && !window._wb_wombat) { - window._wb_wombat = new _WBWombat(window, wbinfo); - } else if (!window._wb_wombat) { - console.warn("_wb_wombat missing!"); + if (window && window._WBWombatInit) { + window._WBWombatInit(); } {% else %} diff --git a/tests/test_integration.py b/tests/test_integration.py index 46bf8b8f..04e3a75a 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -101,7 +101,7 @@ class TestWbIntegration(BaseConfigTest): assert '"20140127171238"' in resp.text, resp.text assert 'wombat.js' in resp.text - assert 'new _WBWombat' in resp.text, resp.text + assert '_WBWombatInit' in resp.text, resp.text assert '/pywb/20140127171238{0}/http://www.iana.org/time-zones"'.format(fmod) in resp.text if fmod == 'mp_': diff --git a/tests/test_memento.py b/tests/test_memento.py index 4f876bbc..3547a258 100644 --- a/tests/test_memento.py +++ b/tests/test_memento.py @@ -73,7 +73,7 @@ class TestMemento(MementoMixin, BaseConfigTest): # Body assert '"20140127171238"' in resp.text assert 'wombat.js' in resp.text - assert 'new _WBWombat' in resp.text, resp.text + assert 'WBWombatInit' in resp.text, resp.text assert '/pywb/20140127171238{0}/http://www.iana.org/time-zones"'.format(fmod) in resp.text def test_memento_at_timegate_latest(self, fmod): diff --git a/tests/test_prefixed_deploy.py b/tests/test_prefixed_deploy.py index cbf853ab..b382a4c3 100644 --- a/tests/test_prefixed_deploy.py +++ b/tests/test_prefixed_deploy.py @@ -38,7 +38,7 @@ class TestPrefixedDeploy(BaseConfigTest): assert "'http://localhost:80/prefix/static/default_banner.js'" in resp.text assert '"http://localhost:80/prefix/static/"' in resp.text assert '"http://localhost:80/prefix/pywb/"' in resp.text - assert 'new _WBWombat' in resp.text, resp.text + assert 'WBWombatInit' in resp.text, resp.text assert '"/prefix/pywb/20140127171238{0}/http://www.iana.org/time-zones"'.format(fmod) in resp.text, resp.text def test_static_content(self): diff --git a/tests/test_redirect_classic.py b/tests/test_redirect_classic.py index 073709e7..9d200e70 100644 --- a/tests/test_redirect_classic.py +++ b/tests/test_redirect_classic.py @@ -19,7 +19,7 @@ class TestRedirectClassic(BaseConfigTest): assert '"20140127171238"' in resp.text, resp.text assert 'wombat.js' in resp.text - assert 'new _WBWombat' in resp.text, resp.text + assert 'WBWombatInit' in resp.text, resp.text assert '/pywb/20140127171238{0}/http://www.iana.org/time-zones"'.format(fmod) in resp.text assert ('wbinfo.is_framed = ' + ('true' if fmod else 'false')) in resp.text diff --git a/tests/test_root_coll.py b/tests/test_root_coll.py index 164c8783..ceffec3b 100644 --- a/tests/test_root_coll.py +++ b/tests/test_root_coll.py @@ -13,7 +13,7 @@ class TestRootColl(BaseConfigTest): # Body assert '"20140127171238"' in resp.text assert 'wombat.js' in resp.text - assert 'new _WBWombat' in resp.text, resp.text + assert 'WBWombatInit' in resp.text, resp.text assert '/20140127171238{0}/http://www.iana.org/time-zones"'.format(fmod) in resp.text def test_root_replay_no_ts(self, fmod): @@ -23,7 +23,7 @@ class TestRootColl(BaseConfigTest): # Body assert 'request_ts = ""' in resp.text assert 'wombat.js' in resp.text - assert 'new _WBWombat' in resp.text, resp.text + assert 'WBWombatInit' in resp.text, resp.text assert '/{0}http://www.iana.org/time-zones"'.format(fmod_slash) in resp.text def test_root_replay_redir(self, fmod):