Multiple instances of a script (iframes) generate multiple instances of variables?

redigerte July 2017 i Development Chrome
I'm writing a script to add a keyboard shortcut to download whatever the mouse cursor is pointing at, specifically for tumblr.

I noticed that I have several instances of the script running for each(?) iframe. I have a variable that holds the URL to the last image pointed at by the cursor.
When I try to update the variable (by pressing shift, or whatever key in the "keydown" event listener), it updates only in one instance, the other one stays undefined.

my current source code here (warning, not clean, some testing function and lots of debug messages):

Here's a page to test it on:

The function in question is the updateLink() one, which updates the currentLink variable.

I doubt there's a way to have this variable common for all instances of the script, unless I deactivate the script for iframes. But if I do that, I can't scrape the entire node tree for images. :(

Any idea on how to work around that?


  • redigerte July 2017 Chrome

    I've made progress I think, I changed to @run-at document-idle and tweaked some functions a bit.

    However, now I get the following error too. Still working though.
    Error: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "" from accessing a cross-origin frame.

    img_links_iframe[i].onmouseenter= function (){ updateLink(this.src); pointed_obj = this; };
    Doesn't work, but it works with onmousemove, albeit a bit more expensive I guess. Weird.

  • redigerte July 2017 Chrome
    Nevermind, it's working now. It was just the testing "IMGmatches" function causing the error.
Logg inn eller Registrer deg for å kommentere.