Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite target: #97

Merged
merged 1 commit into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webrecorder/wombat",
"version": "3.3.8",
"version": "3.3.9",
"main": "index.js",
"license": "AGPL-3.0-or-later",
"author": "Ilya Kreymer, Webrecorder Software",
Expand Down
32 changes: 31 additions & 1 deletion src/wombat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,17 @@ Wombat.prototype.rewriteElem = function(elem) {
case 'SCRIPT':
changed = this.rewriteScript(elem);
break;
case 'A':
changed = this.rewriteAttr(elem, 'href') || changed;
if (elem.hasAttribute('target')) {
var newTarget = this.rewriteAttrTarget(elem.target);
if (newTarget !== elem.target) {
elem.target = newTarget;
changed = true;
}
}
break;

default: {
changed = this.rewriteAttr(elem, 'src');
changed = this.rewriteAttr(elem, 'srcset') || changed;
Expand Down Expand Up @@ -5470,7 +5481,10 @@ Wombat.prototype.initOpenOverride = function() {
var wombat = this;

var open_rewritten = function open(strUrl, strWindowName, strWindowFeatures) {
var rwStrUrl = wombat.rewriteUrl(strUrl, false, '');
if (strWindowName) {
strWindowName = this.rewriteAttrTarget(strWindowName);
}
var rwStrUrl = wombat.rewriteUrl(strUrl, false);
var res = orig.call(
wombat.proxyToObj(this),
rwStrUrl,
Expand All @@ -5496,6 +5510,22 @@ Wombat.prototype.initOpenOverride = function() {
}
};

/**
* Rewrite 'target' for anchor tag or window.open
*/

Wombat.prototype.rewriteAttrTarget = function(target) {
if (!this.wb_info.target_frame) {
return target;
}

if (target === '_blank' || target === '_parent' || target === '_top') {
return this.wb_info.target_frame;
}

return target;
};

/**
* Applies an override to the getter and setter functions of document.cookie
* in order to ensure that cookies are rewritten
Expand Down