1

In an extension I'm working on, I create a new window in focus with a certain URL. When the page is for finished loading, I want to select a particular element by ID and change its value attribute with:

document.getElementById("myDiv").value = myVar;

I create the new window inside an action.js page. I know that generally one can fire a js script when a given page finishes loading using

"run_at": "document_end"

But how can I do this "inline" such that a single script does:

  1. Create in focus window
  2. Wait for Window to load
  3. Change value of some element after load

I currently have a really ugly workaround. At step 2, I call a timeout for 3 seconds that fires an alert. This works, in that, when the user closes the alert, the script modifies the page. Strangely, that solution ONLY works when the timeout function is an alert. I'd be interested in hearing about why that is as well.

J-B-L
  • 55
  • 1
  • 6
  • 1
    Please check related SO post - [On page load event in Chrome extensions](http://stackoverflow.com/questions/9862182/on-page-load-event-in-chrome-extensions). – Teyam May 30 '16 at 08:12
  • This is helpful. However it merely tells me how to do this from within a Background Script or how to execute a content script. My need is SLIGHTLY different, I need to check if a given page is loaded from within an action script. Will chrome.webNavigation.onCompleted work inside a content script? – J-B-L May 30 '16 at 22:51
  • [Content Scripts](https://developer.chrome.com/extensions/content_scripts) have some limitations. They **cannot** use chrome.* APIs. – Teyam May 31 '16 at 09:28

0 Answers0