1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

wombat improvements:

- history change check: don't reject urls without a slash, check if new url == origin
- new api: override window.fetch() if it exists
- srcset elem rewriting, <source> element srcset override
- ajax: don't add X-Pywb-Requested-With header if url is a data: url
This commit is contained in:
Ilya Kreymer 2016-10-19 21:09:15 -07:00
parent 8b77f66a10
commit 42a31bbebf

View File

@ -18,7 +18,7 @@ This file is part of pywb, https://github.com/ikreymer/pywb
*/
//============================================
// Wombat JS-Rewriting Library v2.17
// Wombat JS-Rewriting Library v2.18
//============================================
@ -729,7 +729,9 @@ var wombat_internal = function($wbwindow) {
var abs_url = extract_orig(url);
if (abs_url && !starts_with(abs_url, $wbwindow.WB_wombat_location.origin + "/")) {
if (abs_url &&
(abs_url != $wbwindow.WB_wombat_location.origin) &&
!starts_with(abs_url, $wbwindow.WB_wombat_location.origin + "/")) {
throw new DOMException("Invalid history change: " + abs_url);
}
@ -823,12 +825,34 @@ var wombat_internal = function($wbwindow) {
}
result = orig.call(this, method, url, async, user, password);
this.setRequestHeader('X-Pywb-Requested-With', 'XMLHttpRequest');
if (!starts_with(url, "data:")) {
this.setRequestHeader('X-Pywb-Requested-With', 'XMLHttpRequest');
}
}
$wbwindow.XMLHttpRequest.prototype.open = open_rewritten;
}
//============================================
function init_fetch_rewrite()
{
if (!$wbwindow.fetch) {
return;
}
var orig_fetch = $wbwindow.fetch;
$wbwindow.fetch = function(input, init) {
if (typeof(input) === "string") {
input = rewrite_url(input);
} else if (typeof(input) === "object" && input.url) {
input.url = rewrite_url(input.url);
}
return orig_fetch.call(this, input, init);
}
}
//============================================
function init_base_override()
{
@ -1267,6 +1291,7 @@ var wombat_internal = function($wbwindow) {
changed = rewrite_frame_src(elem, "src");
} else {
changed = rewrite_attr(elem, "src");
changed = rewrite_attr(elem, "srcset") || changed;
changed = rewrite_attr(elem, "href") || changed;
changed = rewrite_attr(elem, "style") || changed;
changed = rewrite_attr(elem, "poster") || changed;
@ -1466,6 +1491,7 @@ var wombat_internal = function($wbwindow) {
override_attr($wbwindow.HTMLAudioElement.prototype, "src", "oe_");
override_attr($wbwindow.HTMLAudioElement.prototype, "poster", "im_");
override_attr($wbwindow.HTMLSourceElement.prototype, "src", "oe_");
override_attr($wbwindow.HTMLSourceElement.prototype, "srcset", "oe_");
override_attr($wbwindow.HTMLInputElement.prototype, "src", "oe_");
override_attr($wbwindow.HTMLEmbedElement.prototype, "src", "oe_");
override_attr($wbwindow.HTMLObjectElement.prototype, "data", "oe_");
@ -2384,6 +2410,9 @@ var wombat_internal = function($wbwindow) {
// Ajax
init_ajax_rewrite();
// Fetch
init_fetch_rewrite();
if (!wb_opts.skip_disable_worker) {
//init_worker_override();
}