The presence of "asbygoogle" in Chrome's executeScript function prevents the script

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&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!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.

Answer №1

Successfully making it function with allFrames set to true, however, only when having runAt specified as document_start.

Under these conditions, the callback unquestionably triggers for the primary document, although I couldn't confirm its execution within the iframe.

Answer №2

Unfortunately, there isn't a feature like "exclude_matches" for manifest permissions that allows you to easily exclude specific URLs like

exclude_matches:"*://*googleads.g.doubleclick.net"
. However, if you want to disable those google ads frames, you have a couple of options:

1) Turn them off;

2) Execute your script.

You can achieve this by running two executeScripts: The first script runs with allframes:false. It locates all frames with the specified host using jquery, querySelectorAll, etc., and sets their src = ""; (you can save the original source before setting it and restore it later). The second script is your main script, which can be run in the callback of the first script.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How come once I close a PrimeNG modal that is defined within a child component, I am unable to reopen it?

Currently, I am developing an Angular application that utilizes PrimeNG. In the process, I encountered a challenge. Initially, I had a component with a PrimeNG Dialog embedded within (refer to this link), and it was functioning properly. To streamline my ...

The chosen options are not appearing. Could this be a problem related to AngularJS?

I am working on setting up a dropdown menu in HTML that includes only the AngularJS tag. This dropdown menu will be used to populate another AngularJS dropdown menu. Below is the code for the first dropdown menu: <select class="form-control" ng-model=" ...

The width of my search bar keeps shifting every time I click on the navbar button

Whenever I switch between the home and about page buttons in the app's navbar, the width of my search bar changes. Why is this happening? (This issue occurs only on desktop). Here is my code: https://github.com/StrikerOne65/snewz ...

Creating a feature in Vuejs that allows for real-time card updates on the screen by sending a post request to the database and

After sending a post request to the database, I need to refresh my cardData array which gets its value from a get request in order to see the changes. The current saveDraft() function adds values to the cardData array, but it requires a page refresh or c ...

Issue with Google Tag Manager click event not propagating to parent element

I am currently configuring Google Tag Manager for a client's website and encountering difficulties in getting click event tags to activate. Although I have set the trigger to activate based on the button's CSS selector, the actual button contain ...

Assigning an argument of type `any` to a parameter of type `Observable<IComboboxItem[]>` can be considered risky

I have a piece of code that retrieves data from the backend server. Here is the code snippet: @Injectable() export class DictionariesDatasourceFacadeService { public invoiceTemplate: IDataSource<IComboboxItem>; public replacedLegalEntity: IData ...

Clearing the canvas completely with CamanJS: a step-by-step guide

I need some help with my CamanJS photo editing app. Everything is working perfectly except for one issue - when a user uploads a new image and applies a filter, the canvas reverts back to the previously uploaded image. Even though I am using the revert() f ...

Can you explain the functionality of the JavaScript code in the index.html file within webpack's react-scripts?

I have been experimenting with dynamically loading a React component into another application that is also a simple React app. However, I am facing challenges getting the index.js file to run properly. While referencing this article for guidance, I notice ...

A guide on storing data in a database with AngularJS within the Django framework

My project utilizes the Django framework along with AngularJS. I am looking to save all the values entered in my HTML page to the Database upon clicking submit. I have heard that a simple submit button is needed and most changes will be made in views.py. S ...

What are the best ways to personalize my code using Angular Devextreme?

Our development team is currently utilizing Angular for the front-end framework and ASP.net for the back-end framework. They are also incorporating Devextreme and Devexpress as libraries, or similar tools. However, there seems to be difficulty in implement ...

When querying a document, the Mongoose array is missing

When querying for documents with an array, I'm encountering an issue where the returned documents do not include the array. Below is my code: Query Code (async () => { const data = await Lesson.find({signed: {$exists: true}}); cons ...

I am struggling to extract data from the spawned Node.js child process. What am I overlooking?

Trying to utilize a spawned command-line process for lzip in order to expand an lzipped data stream due to the lack of suitable native JavaScript tools. Succeeded in achieving this by working with files and file descriptors, although cumbersome to handle ...

Using jQuery to verify the presence of an element, especially one that may have been dynamically inserted via AJAX

I have a good understanding of how to verify elements that are present when the document is loaded: jQuery.fn.exists = function () { return jQuery(this).length > 0; } However, this approach does not detect elements that are dynamically added via A ...

Exploring the Functionality of Computed Properties in Vue.js

I am facing an issue with my Vue component where I am trying to set the image src using data from my api. const product = computed(() => { return store.products.find(product => product.slug === route.params.slug); }); const selectedImage = ref(n ...

Countdown to redirect or exit on Jquery mobile "pageshow" and "pagehide" events

Looking to implement a 30-second countdown on a Jquery Mobile page with specific requirements: (1) Countdown begins on pageshow (2) Redirects to new page when countdown expires (3) If user navigates away (pagehide) before countdown finishes, the timer fun ...

Restricting the length of dynamic dropdowns in a React application

Click here to view the code on CodeSandbox My dropdown menu options are dynamically generated and filtered based on custom data. const dropdownData = [ { code: "others", name: "Others", amenity: [] }, { code: "bed", name: "Bed", ...

Tips on preventing a div from being draggable within another div that is draggable

I have a plugin called Owl-Carousel that allows for sliding functionality. It automatically slides, but you can also manually slide it by dragging the slides. I want to insert some divs inside the slides; however, if the drag starts from that div, I don& ...

Creating adaptable background images with fullpage.js

I'm currently utilizing fullpage.js for parallax scrolling. I'm wondering if there's a way to make the background images adjust responsively when I resize my window. Check out the documentation here: https://github.com/alvarotrigo/fullPage. ...

Removing duplicates from a multidimensional array by comparing the first element in each subarray using Javascript

I need to obtain unique values from a multidimensional array. The uniqueness should be based on the first element of each item. let arr = [['item 1', 'item 2'],['item 1', 'item 5'],['item 3', 'item 4& ...

Ways to turn off default browser tooltip using bootstrap4 tooltip

Check out the code below, which demonstrates displaying both the bootstrap tooltip and the native title-attribute tooltip: This is an example of text with a tooltip using Font Awesome icon: <i class="far fa-question-circle" data-toggle="tooltip" title= ...