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

wombat customization: pass custom options from config.yaml 'rewrite_opts.client' as a json obj

to wombat.js #96
currently supporting no_rewrite_prefixes, and skipping dom, setAttribute and postmessage overrides
(used by via.hypothes.is) -- other options to be added later
This commit is contained in:
Ilya Kreymer 2015-04-16 12:24:01 -07:00
parent 2e4427100c
commit 74c6b60d5e
3 changed files with 25 additions and 5 deletions

View File

@ -99,6 +99,7 @@ class WbRequest(object):
self.query_filter = []
self.custom_params = {}
self.user_metadata = user_metadata
self.rewrite_opts = rewrite_opts
# PERF
env['X_PERF'] = {}

View File

@ -31,6 +31,9 @@ _WBWombat = (function() {
var wb_wombat_updating = false;
// custom options
var wb_opts;
//============================================
function is_host_url(str) {
// Good guess that's its a hostname
@ -152,6 +155,13 @@ _WBWombat = (function() {
return url;
}
// OPTS: additional ignore prefixes
if (wb_opts.norewrite_prefixes) {
if (starts_with(url, wb_opts.no_rewrite_prefixes)) {
return url;
}
}
// If starts with prefix, no rewriting needed
// Only check replay prefix (no date) as date may be different for each
// capture
@ -927,6 +937,8 @@ _WBWombat = (function() {
function wombat_init(wbinfo) {
wb_replay_prefix = wbinfo.prefix;
wb_opts = wbinfo.wombat_opts || {};
if (wb_replay_prefix) {
wb_replay_date_prefix = wb_replay_prefix + wbinfo.wombat_ts + wbinfo.mod + "/";
@ -1019,7 +1031,10 @@ _WBWombat = (function() {
init_open_override();
// postMessage
init_postmessage_override();
// OPT skip
if (!wb_opts.skip_postmessage) {
init_postmessage_override();
}
// write
init_write_override();
@ -1032,8 +1047,9 @@ _WBWombat = (function() {
init_mutation_obs();
// setAttribute
init_setAttribute_override();
if (!wb_opts.skip_setAttribute) {
init_setAttribute_override();
}
// ensure namespace urls are NOT rewritten
init_createElementNS_fix();
@ -1044,7 +1060,10 @@ _WBWombat = (function() {
init_cookies_override();
// DOM
init_dom_override();
// OPT skip
if (!wb_opts.skip_dom) {
init_dom_override();
}
// Random
init_seeded_random(wbinfo.wombat_sec);

View File

@ -23,7 +23,7 @@
wbinfo.wombat_host = "{{ urlsplit.netloc }}";
wbinfo.wombat_sec = "{{ cdx.timestamp | format_ts('%s') }}";
wbinfo.wombat_opts = {{ wbrequest.rewrite_opts.client | tojson if wbrequest.rewrite_opts.client else 'undefined' }};
wbinfo.wombat_opts = {{ wbrequest.rewrite_opts.client | tojson if wbrequest.rewrite_opts.client else '{}' }};
if (window && window._WBWombat && !window._wb_js_inited) {
var _wb_wombat = new _WBWombat(wbinfo);