I’m executing the following (modified for demo) script in the console of x.com
There is no cross-domain issues. But the function executes immediately – which results in an error because the DOM is not loaded (I can see visually).
If I set a timeout setTimeout(parsefn,9000)
(ensuring dom is loaded), it works fine.
If I execute newWindow.onload()
after dom load, it works fine.
Reading stackoverflow and what not – indicates the code should be working … ? How do I get the code to work – that is execute the function when the child window dom is loaded.
On the latest version of Chrome browser.
let newWindow;
function tweetGet(url wait) {
newWindow = window.open(url,'_blank',"status,heigh​t=600,width=800");
const parsefn = function(event) {
const tweet = [url];
tweet.push(newWindow.document.querySelectorAll("time")[0].getAttribute("datetime"));
newWindow.close();
console.log(tweet);
}
newWindow.document.body.onload = parsefn;
}
tweetGet("https://x.com/VillaCollegeMv/status/1817893326437425374")