mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 15:09:54 +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
|
||||
var wb_opts;
|
||||
|
||||
var wb_is_proxy = false;
|
||||
|
||||
//============================================
|
||||
function is_host_url(str) {
|
||||
// Good guess that's its a hostname
|
||||
@ -160,10 +162,12 @@ var wombat_internal = function($wbwindow) {
|
||||
return url;
|
||||
}
|
||||
|
||||
// proxy mode: If no wb_replay_prefix, only rewrite https:// -> http://
|
||||
if (!wb_replay_prefix) {
|
||||
if (starts_with(url, HTTPS_PREFIX)) {
|
||||
// proxy mode: If no wb_replay_prefix, only rewrite scheme
|
||||
if (wb_is_proxy) {
|
||||
if (wb_orig_scheme == HTTP_PREFIX && starts_with(url, HTTPS_PREFIX)) {
|
||||
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 {
|
||||
return url;
|
||||
}
|
||||
@ -317,7 +321,7 @@ var wombat_internal = function($wbwindow) {
|
||||
var orig_href = href;
|
||||
|
||||
// proxy mode: no extraction needed
|
||||
if (!wb_replay_prefix) {
|
||||
if (wb_is_proxy) {
|
||||
return href;
|
||||
}
|
||||
|
||||
@ -2282,12 +2286,24 @@ var wombat_internal = function($wbwindow) {
|
||||
wb_info = wbinfo;
|
||||
wb_opts = wbinfo.wombat_opts;
|
||||
wb_replay_prefix = wbinfo.prefix;
|
||||
wb_is_proxy = (!wb_replay_prefix);
|
||||
|
||||
wb_info.top_host = wb_info.top_host || "*";
|
||||
|
||||
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);
|
||||
|
||||
wb_curr_host = $wbwindow.location.protocol + "//" + $wbwindow.location.host;
|
||||
|
||||
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);
|
||||
} else {
|
||||
@ -2295,11 +2311,6 @@ var wombat_internal = function($wbwindow) {
|
||||
}
|
||||
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_replay_date_prefix = wb_replay_prefix + ts_mod;
|
||||
//wb_coll_prefix += ts_mod;
|
||||
@ -2310,14 +2321,9 @@ var wombat_internal = function($wbwindow) {
|
||||
wb_capture_date_part = "";
|
||||
}
|
||||
|
||||
wb_orig_scheme = wbinfo.wombat_scheme + '://';
|
||||
|
||||
wb_orig_origin = wb_orig_scheme + wbinfo.wombat_host;
|
||||
|
||||
init_bad_prefixes(wb_replay_prefix);
|
||||
}
|
||||
|
||||
init_wombat_loc($wbwindow);
|
||||
|
||||
//if ($wbwindow.opener) {
|
||||
// $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("forward");
|
||||
|
||||
// open
|
||||
init_open_override();
|
||||
|
||||
// postMessage
|
||||
// OPT skip
|
||||
if (!wb_opts.skip_postmessage) {
|
||||
@ -2398,6 +2401,16 @@ var wombat_internal = function($wbwindow) {
|
||||
init_dom_override();
|
||||
}
|
||||
|
||||
// registerProtocolHandler override
|
||||
init_registerPH_override();
|
||||
|
||||
//sendBeacon override
|
||||
init_beacon_override();
|
||||
}
|
||||
|
||||
// other overrides
|
||||
// proxy mode: only using these overrides
|
||||
|
||||
// Random
|
||||
init_seeded_random(wbinfo.wombat_sec);
|
||||
|
||||
@ -2407,11 +2420,8 @@ var wombat_internal = function($wbwindow) {
|
||||
// Date
|
||||
init_date_override(wbinfo.wombat_sec);
|
||||
|
||||
// registerProtocolHandler override
|
||||
init_registerPH_override();
|
||||
|
||||
//sendBeacon override
|
||||
init_beacon_override();
|
||||
// open
|
||||
init_open_override();
|
||||
|
||||
// expose functions
|
||||
this.extract_orig = extract_orig;
|
||||
@ -2422,7 +2432,7 @@ var wombat_internal = function($wbwindow) {
|
||||
|
||||
function init_top_frame($wbwindow) {
|
||||
// proxy mode
|
||||
if (!wb_replay_prefix) {
|
||||
if (wb_is_proxy) {
|
||||
$wbwindow.__WB_replay_top = $wbwindow.top;
|
||||
$wbwindow.__WB_top_frame = undefined;
|
||||
return;
|
||||
|
@ -38,7 +38,7 @@
|
||||
{% include banner_html ignore missing %}
|
||||
|
||||
<!-- 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 -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user