Skip to content

Commit

Permalink
fix(injection): catch error if iframe is cross origin; #312
Browse files Browse the repository at this point in the history
  • Loading branch information
sereneblue committed Apr 28, 2020
1 parent 62062f6 commit 94b3c8f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/lib/chameleon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ export class Chameleon {

wlRule.spoofIP = prev.whitelist.urlList[i].spoofIP;
wlRule.profile = prev.whitelist.urlList[i].profile === 'default' ? 'default' : mappedProfiles[prev.whitelist.urlList[i].profile];

let tempLang = languages.find(l => l.value === prev.whitelist.urlList[i].lang);
wlRule.lang = tempLang ? tempLang.code : 'en-US';

Expand Down
48 changes: 38 additions & 10 deletions src/lib/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,27 @@ class Injector {
contentWindow: {
get: function() {
let f = iframeWindow.apply(this);
if (f) {
f.Date = window.Date;
f.Intl.DateTimeFormat = window.Intl.DateTimeFormat;
f.screen = window.screen;
f.navigator = window.navigator;
}
try {
if (f) {
Object.defineProperty(f, 'Date', {
value: window.Date
});
Object.defineProperty(f.Intl, 'DateTimeFormat', {
value: window.Intl.DateTimeFormat
});
Object.defineProperty(f, 'screen', {
value: window.screen
});
Object.defineProperty(f, 'navigator', {
value: window.navigator
});
}
} catch (e) {}
return f;
}
},
Expand All @@ -304,10 +319,23 @@ class Injector {
get: function() {
let f = frameWindow.apply(this);
if (f) {
f.Date = window.Date;
f.Intl.DateTimeFormat = window.Intl.DateTimeFormat;
f.screen = window.screen;
f.navigator = window.navigator;
try {
Object.defineProperty(f, 'Date', {
value: window.Date
});
Object.defineProperty(f.Intl, 'DateTimeFormat', {
value: window.Intl.DateTimeFormat
});
Object.defineProperty(f, 'screen', {
value: window.screen
});
Object.defineProperty(f, 'navigator', {
value: window.navigator
});
} catch (e) {}
}
return f;
}
Expand Down

0 comments on commit 94b3c8f

Please sign in to comment.