mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-28 00:25:21 +01:00
client rewrite: improvements for proxy mode
- disable most overrides when in proxy mode - if using rewrite_url(), keep current scheme, instead of defaulting to http - use 'window._wb_js' to check init
This commit is contained in:
parent
bdf4f9bc71
commit
718cd43ae2
@ -18,7 +18,7 @@ This file is part of pywb, https://github.com/ikreymer/pywb
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//============================================
|
//============================================
|
||||||
// Wombat JS-Rewriting Library v2.16
|
// Wombat JS-Rewriting Library v2.17
|
||||||
//============================================
|
//============================================
|
||||||
|
|
||||||
|
|
||||||
@ -50,6 +50,8 @@ var wombat_internal = function($wbwindow) {
|
|||||||
// custom options
|
// custom options
|
||||||
var wb_opts;
|
var wb_opts;
|
||||||
|
|
||||||
|
var wb_is_proxy = false;
|
||||||
|
|
||||||
//============================================
|
//============================================
|
||||||
function is_host_url(str) {
|
function is_host_url(str) {
|
||||||
// Good guess that's its a hostname
|
// Good guess that's its a hostname
|
||||||
@ -160,10 +162,12 @@ var wombat_internal = function($wbwindow) {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// proxy mode: If no wb_replay_prefix, only rewrite https:// -> http://
|
// proxy mode: If no wb_replay_prefix, only rewrite scheme
|
||||||
if (!wb_replay_prefix) {
|
if (wb_is_proxy) {
|
||||||
if (starts_with(url, HTTPS_PREFIX)) {
|
if (wb_orig_scheme == HTTP_PREFIX && starts_with(url, HTTPS_PREFIX)) {
|
||||||
return HTTP_PREFIX + url.substr(HTTPS_PREFIX.length);
|
return HTTP_PREFIX + url.substr(HTTPS_PREFIX.length);
|
||||||
|
} else if (wb_orig_scheme == HTTPS_PREFIX && starts_with(url, HTTP_PREFIX)) {
|
||||||
|
return HTTPS_PREFIX + url.substr(HTTP_PREFIX.length);
|
||||||
} else {
|
} else {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
@ -317,7 +321,7 @@ var wombat_internal = function($wbwindow) {
|
|||||||
var orig_href = href;
|
var orig_href = href;
|
||||||
|
|
||||||
// proxy mode: no extraction needed
|
// proxy mode: no extraction needed
|
||||||
if (!wb_replay_prefix) {
|
if (wb_is_proxy) {
|
||||||
return href;
|
return href;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2282,12 +2286,24 @@ var wombat_internal = function($wbwindow) {
|
|||||||
wb_info = wbinfo;
|
wb_info = wbinfo;
|
||||||
wb_opts = wbinfo.wombat_opts;
|
wb_opts = wbinfo.wombat_opts;
|
||||||
wb_replay_prefix = wbinfo.prefix;
|
wb_replay_prefix = wbinfo.prefix;
|
||||||
|
wb_is_proxy = (!wb_replay_prefix);
|
||||||
|
|
||||||
wb_info.top_host = wb_info.top_host || "*";
|
wb_info.top_host = wb_info.top_host || "*";
|
||||||
|
|
||||||
init_top_frame($wbwindow);
|
init_top_frame($wbwindow);
|
||||||
|
|
||||||
|
init_wombat_loc($wbwindow);
|
||||||
|
|
||||||
|
wbinfo.wombat_opts = wbinfo.wombat_opts || {};
|
||||||
|
|
||||||
|
wb_orig_scheme = wbinfo.wombat_scheme + '://';
|
||||||
|
|
||||||
|
// archival mode: init url-rewriting intercepts
|
||||||
|
if (!wb_is_proxy) {
|
||||||
init_wombat_top($wbwindow);
|
init_wombat_top($wbwindow);
|
||||||
|
|
||||||
|
wb_curr_host = $wbwindow.location.protocol + "//" + $wbwindow.location.host;
|
||||||
|
|
||||||
if (wb_replay_prefix && wb_replay_prefix.indexOf($wbwindow.__WB_replay_top.location.origin) == 0) {
|
if (wb_replay_prefix && wb_replay_prefix.indexOf($wbwindow.__WB_replay_top.location.origin) == 0) {
|
||||||
wb_rel_prefix = wb_replay_prefix.substring($wbwindow.__WB_replay_top.location.origin.length + 1);
|
wb_rel_prefix = wb_replay_prefix.substring($wbwindow.__WB_replay_top.location.origin.length + 1);
|
||||||
} else {
|
} else {
|
||||||
@ -2295,11 +2311,6 @@ var wombat_internal = function($wbwindow) {
|
|||||||
}
|
}
|
||||||
wb_rel_prefix_check = wb_rel_prefix;
|
wb_rel_prefix_check = wb_rel_prefix;
|
||||||
|
|
||||||
wbinfo.wombat_opts = wbinfo.wombat_opts || {};
|
|
||||||
|
|
||||||
wb_curr_host = $wbwindow.location.protocol + "//" + $wbwindow.location.host;
|
|
||||||
|
|
||||||
if (wb_replay_prefix) {
|
|
||||||
wb_abs_prefix = wb_replay_prefix;
|
wb_abs_prefix = wb_replay_prefix;
|
||||||
//wb_replay_date_prefix = wb_replay_prefix + ts_mod;
|
//wb_replay_date_prefix = wb_replay_prefix + ts_mod;
|
||||||
//wb_coll_prefix += ts_mod;
|
//wb_coll_prefix += ts_mod;
|
||||||
@ -2310,14 +2321,9 @@ var wombat_internal = function($wbwindow) {
|
|||||||
wb_capture_date_part = "";
|
wb_capture_date_part = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
wb_orig_scheme = wbinfo.wombat_scheme + '://';
|
|
||||||
|
|
||||||
wb_orig_origin = wb_orig_scheme + wbinfo.wombat_host;
|
wb_orig_origin = wb_orig_scheme + wbinfo.wombat_host;
|
||||||
|
|
||||||
init_bad_prefixes(wb_replay_prefix);
|
init_bad_prefixes(wb_replay_prefix);
|
||||||
}
|
|
||||||
|
|
||||||
init_wombat_loc($wbwindow);
|
|
||||||
|
|
||||||
//if ($wbwindow.opener) {
|
//if ($wbwindow.opener) {
|
||||||
// $wbwindow.opener.WB_wombat_location = copy_location_obj($wbwindow.opener.location);
|
// $wbwindow.opener.WB_wombat_location = copy_location_obj($wbwindow.opener.location);
|
||||||
@ -2337,9 +2343,6 @@ var wombat_internal = function($wbwindow) {
|
|||||||
override_history_nav("back");
|
override_history_nav("back");
|
||||||
override_history_nav("forward");
|
override_history_nav("forward");
|
||||||
|
|
||||||
// open
|
|
||||||
init_open_override();
|
|
||||||
|
|
||||||
// postMessage
|
// postMessage
|
||||||
// OPT skip
|
// OPT skip
|
||||||
if (!wb_opts.skip_postmessage) {
|
if (!wb_opts.skip_postmessage) {
|
||||||
@ -2398,6 +2401,16 @@ var wombat_internal = function($wbwindow) {
|
|||||||
init_dom_override();
|
init_dom_override();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// registerProtocolHandler override
|
||||||
|
init_registerPH_override();
|
||||||
|
|
||||||
|
//sendBeacon override
|
||||||
|
init_beacon_override();
|
||||||
|
}
|
||||||
|
|
||||||
|
// other overrides
|
||||||
|
// proxy mode: only using these overrides
|
||||||
|
|
||||||
// Random
|
// Random
|
||||||
init_seeded_random(wbinfo.wombat_sec);
|
init_seeded_random(wbinfo.wombat_sec);
|
||||||
|
|
||||||
@ -2407,11 +2420,8 @@ var wombat_internal = function($wbwindow) {
|
|||||||
// Date
|
// Date
|
||||||
init_date_override(wbinfo.wombat_sec);
|
init_date_override(wbinfo.wombat_sec);
|
||||||
|
|
||||||
// registerProtocolHandler override
|
// open
|
||||||
init_registerPH_override();
|
init_open_override();
|
||||||
|
|
||||||
//sendBeacon override
|
|
||||||
init_beacon_override();
|
|
||||||
|
|
||||||
// expose functions
|
// expose functions
|
||||||
this.extract_orig = extract_orig;
|
this.extract_orig = extract_orig;
|
||||||
@ -2422,7 +2432,7 @@ var wombat_internal = function($wbwindow) {
|
|||||||
|
|
||||||
function init_top_frame($wbwindow) {
|
function init_top_frame($wbwindow) {
|
||||||
// proxy mode
|
// proxy mode
|
||||||
if (!wb_replay_prefix) {
|
if (wb_is_proxy) {
|
||||||
$wbwindow.__WB_replay_top = $wbwindow.top;
|
$wbwindow.__WB_replay_top = $wbwindow.top;
|
||||||
$wbwindow.__WB_top_frame = undefined;
|
$wbwindow.__WB_top_frame = undefined;
|
||||||
return;
|
return;
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
{% include banner_html ignore missing %}
|
{% include banner_html ignore missing %}
|
||||||
|
|
||||||
<!-- load banner -->
|
<!-- load banner -->
|
||||||
<script> if (_wb_js) { _wb_js.load(); }</script>
|
<script> if (window._wb_js) { _wb_js.load(); }</script>
|
||||||
|
|
||||||
{#
|
{#
|
||||||
<!-- workaround for chrome iframe scrolling issue -->
|
<!-- workaround for chrome iframe scrolling issue -->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user