Skip to content

Commit

Permalink
Rewrite: Support target rewriting, open new windows in top-frame inst…
Browse files Browse the repository at this point in the history
…ead (#767)

* Bump wombat to 3.3.9

* Set target attributes to iframe name
  • Loading branch information
tw4l committed Oct 19, 2022
1 parent f46facb commit c513fe1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pywb/rewrite/html_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ def _rewrite_tag_attrs(self, tag, tag_attrs, set_parsing_context=True):
# URL not skipped, likely src='js/....', forcing abs to make sure, cause PHP MIME(JS) === HTML
attr_value = self._rewrite_url(attr_value, rw_mod, True)
self._write_attr('__wb_orig_src', ov, empty_attr=None)

elif attr_name == 'target':
target = attr_value
if target in ('_blank', '_parent', '_top'):
attr_value = '___wb_replay_top_frame'

else:
# rewrite url using tag handler
rw_mod = handler.get(attr_name)
Expand Down
3 changes: 3 additions & 0 deletions pywb/rewrite/test/test_html_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@
>>> parse('<!--[if !IE]> --><html><![endif]--><a href="http://example.com/"><!--[if IE]><![endif]--><a href="http://example.com/"></html>')
<!--[if !IE]> --><html><![endif]><a href="/web/20131226101010/http://example.com/"><!--[if IE]><![endif]--><a href="/web/20131226101010/http://example.com/"></html>
# Test tag with a target
>>> parse('<HTML><A Href=\"page.html\" target=\"_blank\">Text</a></hTmL>')
<html><a href="page.html" target="___wb_replay_top_frame">Text</a></html>
# Test blank
>>> parse('')
Expand Down
2 changes: 2 additions & 0 deletions pywb/static/wb_frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ ContentFrame.prototype.init_iframe = function() {
return;
}

this.iframe.setAttribute("name", "___wb_replay_top_frame");

this.extract_prefix();
if (window.WBBanner) {
this.wbBanner = window.WBBanner;
Expand Down
2 changes: 1 addition & 1 deletion pywb/static/wombat.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pywb/static/wombatProxyMode.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pywb/templates/head_insert.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
wbinfo.proxy_magic = "{{ env.pywb_proxy_magic }}";
wbinfo.static_prefix = "{{ static_prefix }}/";
wbinfo.enable_auto_fetch = {{ config.enable_auto_fetch | tobool }};
wbinfo.target_frame = "___wb_replay_top_frame";
</script>
{% if env.pywb_proxy_magic %}
{% set whichWombat = 'wombatProxyMode.js' %}
Expand Down

0 comments on commit c513fe1

Please sign in to comment.