Index: include.preload.js |
=================================================================== |
--- a/include.preload.js |
+++ b/include.preload.js |
@@ -79,22 +79,29 @@ |
ext.backgroundPage.sendMessage({type: "add-sitekey", token: attr}); |
} |
-function isInlineFrame(element) |
+function isFrameWithoutContentScript(element) |
{ |
- var contentDocument; |
+ var contentWindow; |
try |
{ |
- contentDocument = element.contentDocument; |
+ contentWindow = element.contentWindow; |
Wladimir Palant
2015/03/04 19:31:36
Accessing element.contentWindow is actually allowe
Sebastian Noack
2015/03/04 20:36:13
You are right. Also I realized that we can actuall
|
} |
catch (e) |
{ |
- return false; // third-party |
+ // This is a third-party frame. Hence we can't access it. |
+ // But that's fine, our content script should already run there. |
+ return false; |
} |
- if (!contentDocument) |
- return false; // not a frame |
+ // The element isn't a <frame>, <iframe> or <object> with "data" attribute. |
+ if (!contentWindow) |
+ return false; |
- return contentDocument.location.protocol == "about:"; |
+ // Return true, if the element is a first-party frame which doesn't |
+ // have this function, hence our content script isn't running there. |
+ // Those are dynamically created frames as well as frames |
+ // with "about:blank", "about:srcdoc" and "javascript:" URL. |
+ return !("isFrameWithoutContentScript" in contentWindow); |
Wladimir Palant
2015/03/04 19:31:36
I wonder whether there can be any timing issues he
Sebastian Noack
2015/03/04 20:36:13
Yes, I tested it on a few websites of course, but
|
} |
function reinjectRulesWhenRemoved(document, style) |
@@ -256,7 +263,7 @@ |
// about:srcdoc and javascript: URLs. Moreover, as of Chrome 40 |
// "load" and "error" events aren't dispatched there. So we have |
// to apply element hiding and collapsing from the parent frame. |
- if (/\bChrome\//.test(navigator.userAgent) && isInlineFrame(element)) |
+ if (/\bChrome\//.test(navigator.userAgent) && isFrameWithoutContentScript(element)) |
{ |
init(element.contentDocument); |