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:
- Create in focus window
- Wait for Window to load
- 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.