I am facing an issue with my Chrome extension that injects javascript into all frames using the code snippet below:
chrome.tabs.executeScript(tabId, { file: "findDoc.js", allFrames:true }, function () {
... }
Everything works well except when the document contains adsbygoogle, as seen in the examples here and here. In the latter case, the executeScript function seems to get stuck and the callback is never triggered.
The adsbygoogle block causing the issue looks like this:
<div id="sponsor" style="display:block">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- CWSJ Front&Article Page (Native-Right) -->
<ins class="adsbygoogle"
style="display:inline-block;width:336px;height:280px"
data-ad-client="ca-pub-4620242196338906"
data-ad-slot="6183624152"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
I have tried different runAt options but none seem to work. It's almost as if the adsbygoogle content is blocking the execution of executeScript.
The Google Ads are definitely within a frame, so setting allFrames:false should theoretically bypass this issue (but it doesn't). The iframe for Google's ad looks like this:
<iframe width="336" height="280" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&&s.handlers,h=H&&H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&&d&&(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_0" name="aswift_0" style="left:0;position:absolute;top:0;"></iframe>
Update: After further investigation, I realized that I had two scripts injecting with allFrames set to true. When I changed allframes to false, the issue was resolved. Now, my main concern is how to target only specific frames like the adsbygoogle frame while still keeping allFrames set to true. Even a simple script like 'console.log' causes executeScript to hang on the Adwords frame.
Update 2: Strangely, even when the injected script is empty (all commented out), executeScript still gets stuck on the Adwords frame without returning.