0

Referencing this question/answer...

I have a Chrome Extension content script that I want to interact with iFrames on a specific page. I can see that my content script executes before the page finishes loading...

I tried adding document ready (which I haven't done before - I didn't think it applied to a content script) and it just executes first - before everything else.

$(document).ready(function () {
  console.log('DOM finally loaded with iFrame...');
});

Here is my manifest section on content_scripts - I just added the document_idle based on the discussion in the linked question.

Is it possible to have code in a content script wait for the complete page load (including iFrames)? Or do I need to add listeners to the content script that 'see' elements I know will finally appear, then take action?

"content_scripts": [
    {
        "matches": ["http://*/*","https://*/*"],
        "js": ["/dscripts/jquery-3.1.1.min.js", "/scripts/content.js"],
        "all_frames" : true,
        "match_about_blank": true,
        "run_at": "document_idle"
    }
],
11teenth
  • 1,853
  • 1
  • 15
  • 28
  • AFAICT there is a standard DOM event which does exactly what you want - [load](https://devdocs.io/dom_events/load) which is fired on `window`. – wOxxOm May 12 '18 at 14:26
  • Yep, just tried it on nytimes.com. However it won't wait for dynamically added iframes, of course. – wOxxOm May 12 '18 at 14:32
  • Thanks guys - happy to accept an answer if you want to write it. I think my mental model was a little backwards...I've ended up just listening for a user click of the element I want - which will only happen when the page is fully loaded (iFrames too)...which is what I was after all along anyway. I was trying to add listeners for an element...when really I can just use focusin and check the element activated. – 11teenth May 12 '18 at 17:09

0 Answers0