From 7234bc51f0380a81325af1106a6a196c2e13d987 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Tue, 13 Feb 2018 13:49:10 -0800 Subject: [PATCH] client-side top-frame notification fix: - send_top_message() to wrap all postMessage calls - url change, hash change, history change notifications only sent if window is top replay frame, cookie notification sent for all windows - don't send url change notification if 'about:blank' or 'javascript:' url bump version to 2.0.2 --- README.rst | 4 ++-- pywb/__init__.py | 2 +- pywb/static/wombat.js | 48 +++++++++++++++++++++++++------------------ 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/README.rst b/README.rst index db7ee66a..eeccf079 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ -Webrecorder pywb 2.0.0 -====================== +Webrecorder pywb 2.0 +==================== .. image:: https://travis-ci.org/webrecorder/pywb.svg?branch=master :target: https://travis-ci.org/webrecorder/pywb diff --git a/pywb/__init__.py b/pywb/__init__.py index 890d3d62..e63045ad 100644 --- a/pywb/__init__.py +++ b/pywb/__init__.py @@ -1,4 +1,4 @@ -__version__ = '2.0.1' +__version__ = '2.0.2' DEFAULT_CONFIG = 'pywb/default_config.yaml' diff --git a/pywb/static/wombat.js b/pywb/static/wombat.js index f705d8ea..299d7ba6 100644 --- a/pywb/static/wombat.js +++ b/pywb/static/wombat.js @@ -18,7 +18,7 @@ This file is part of pywb, https://github.com/webrecorder/pywb */ //============================================ -// Wombat JS-Rewriting Library v2.52 +// Wombat JS-Rewriting Library v2.53 //============================================ @@ -795,18 +795,16 @@ var _WBWombat = function($wbwindow, wbinfo) { //============================================ function send_history_update(url, title) { - if ($wbwindow.__WB_top_frame && $wbwindow == $wbwindow.__WB_replay_top) { - var message = { - "url": url, - "ts": wb_info.timestamp, - "request_ts": wb_info.request_ts, - "is_live": wb_info.is_live, - "title": title, - "wb_type": "replace-url", - } + var message = { + "url": url, + "ts": wb_info.timestamp, + "request_ts": wb_info.request_ts, + "is_live": wb_info.is_live, + "title": title, + "wb_type": "replace-url", + } - $wbwindow.__WB_top_frame.postMessage(message, wb_info.top_host); - } + send_top_message(message); } //============================================ @@ -2141,9 +2139,7 @@ var _WBWombat = function($wbwindow, wbinfo) { "hash": $wbwindow.location.hash } - if ($wbwindow.__WB_top_frame) { - $wbwindow.__WB_top_frame.postMessage(message, wb_info.top_host); - } + send_top_message(message); } $wbwindow.addEventListener("message", receive_hash_change); @@ -2485,9 +2481,7 @@ var _WBWombat = function($wbwindow, wbinfo) { } // norify of cookie setting to allow server-side tracking - if ($wbwindow.__WB_top_frame) { - $wbwindow.__WB_top_frame.postMessage(message, wb_info.top_host); - } + send_top_message(message, true); // if no subdomain, eg. "localhost", just remove domain altogether if ($wbwindow.location.hostname.indexOf(".") >= 0 && !IP_RX.test($wbwindow.location.hostname)) { @@ -3289,7 +3283,9 @@ var _WBWombat = function($wbwindow, wbinfo) { return; } - if (typeof($wbwindow.WB_wombat_location.href) != "string") { + var url = $wbwindow.WB_wombat_location.href; + + if (typeof(url) != "string" || url == "about:blank" || url.indexOf("javascript:") == 0) { return; } @@ -3303,7 +3299,7 @@ var _WBWombat = function($wbwindow, wbinfo) { "wb_type": "load" } - $wbwindow.__WB_top_frame.postMessage(message, wbinfo.top_host); + send_top_message(message); } if ($wbwindow.document.readyState == "complete") { @@ -3315,6 +3311,18 @@ var _WBWombat = function($wbwindow, wbinfo) { } } + function send_top_message(message, skip_top_check) { + if (!$wbwindow.__WB_top_frame) { + return; + } + + if (!skip_top_check && $wbwindow != $wbwindow.__WB_replay_top) { + return; + } + + $wbwindow.__WB_top_frame.postMessage(message, wbinfo.top_host); + } + function init_top_frame($wbwindow) { // proxy mode if (wb_is_proxy) {