Skip to content

Commit cee3c8c

Browse files
committed
new wombat! refactor of rewriting:
- use defineProperty overrides on element prototypes - postMessage() rework: store actual origin with helper function __WB_pmw(window), from server side rewrite - Use window.URL (or external jsurl script) to override all properties of HTMLAnchorElement, override getAttribute() to return original - rename window -> $wbwindow
1 parent 158b047 commit cee3c8c

File tree

3 files changed

+476
-319
lines changed

3 files changed

+476
-319
lines changed

pywb/rewrite/regex_rewriters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ class JSLocationRewriterMixin(object):
132132
def __init__(self, rewriter, rules=[], prefix='WB_wombat_'):
133133
rules = rules + [
134134
# (r'(?<![/$])\blocation\b(?!\":)', RegexRewriter.add_prefix(prefix), 0),
135-
(r'(?<![/$\'"-])\blocation\b(?!(?:\":|=\d|-))', RegexRewriter.add_prefix(prefix), 0),
135+
(r'(?<![/$\'"-])\blocation\b(?!(?:\":|:|=\d|-))', RegexRewriter.add_prefix(prefix), 0),
136+
137+
(r'(?<=\.)postMessage\b\(', RegexRewriter.add_prefix('__WB_pmw(window).'), 0),
136138

137139
# (r'(?<=document\.)domain', RegexRewriter.add_prefix(prefix), 0),
138140
# (r'(?<=document\.)referrer', RegexRewriter.add_prefix(prefix), 0),

pywb/rules.yaml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
rules:
22

3+
34
# twitter rules
45
#=================================================================
56
- url_prefix: 'com,twitter)/i/profiles/show/'
67

78
fuzzy_lookup: '/profiles/show/.*with_replies\?.*(max_id=[^&]+)'
89

9-
- url_prefix: 'com,twimg,abs)/c/swift/en/bundle/boot'
10+
# - url_prefix: 'comx,twimg,abs)/c/swift/en/bundle/boot'
1011

11-
rewrite:
12-
js_rewrite_location: urls
13-
js_regexs:
14-
- match: 'window.location'
15-
replace: 'window.WB_wombat_location'
12+
# rewrite:
13+
# js_rewrite_location: urls
14+
# js_regexs:
15+
# - match: 'window.location'
16+
# replace: 'window.WB_wombat_location'
1617

17-
- match: 'document.location'
18-
replace: 'document.WB_wombat_location'
18+
# - match: 'document.location'
19+
# replace: 'document.WB_wombat_location'
1920

2021
#- url_prefix: 'com,twimg,ton)/'
2122

2223
# rewrite:
2324
# js_rewrite_location: all
2425

25-
- url_prefix: 'com,twimg,amp)/amplify-web-player/prod/js/build.min.js'
26+
# - url_prefix: 'comx,twimg,amp)/amplify-web-player/prod/js/build.min.js'
2627

27-
rewrite:
28+
# rewrite:
2829
#js_rewrite_location: all
29-
js_regexs:
30-
- match: ';$'
31-
replace: '; $(function() {{ var div = $(".poster-image")[0]; window._wb_wombat.watch_elem(div, function(elem) {{ if (elem.tagName == "IMG") {{ elem.setAttribute("width", $(div).width()); elem.setAttribute("height", $(div).height()); }} }}) }} );'
30+
# js_regexs:
31+
# - match: ';$'
32+
# replace: '; $(function() {{ var div = $(".poster-image")[0]; window._wb_wombat.watch_elem(div, function(elem) {{ if (elem.tagName == "IMG") {{ elem.setAttribute("width", $(div).width()); elem.setAttribute("height", $(div).height()); }} }}) }} );'
3233

3334

3435
# facebook rules
@@ -168,17 +169,18 @@ rules:
168169
# vine
169170
- url_prefix: 'co,vine,cdn,'
170171

171-
rewrite:
172-
js_rewrite_location: urls
173-
js_regexs:
174-
- match: 'window.location'
175-
replace: 'WB_wombat_location'
172+
# rewrite:
173+
# js_rewrite_location: urls
174+
# js_regexs:
175+
# - match: 'window.location'
176+
# replace: 'WB_wombat_location'
176177

177178
fuzzy_lookup:
178179
replace: 'videos'
179180
match: 'videos(?:_[^/]+)?/([^?]+)'
180181

181182
# disqus
183+
#- url_prefix: ['com,disqus', 'com,disquscdn']
182184
- url_prefix: 'com,disqus'
183185

184186
rewrite:

0 commit comments

Comments
 (0)