How to run a script on a page without having to open it in a browser tab or window?

4

I need to do a web-extension (add-on) that can manipulate DOM elements, existing events and execute scripts in the context of a page in a website.

But do I need this to happen in background without the page being explicitly in the user's browser, ie do I want to manipulate a page without opening it in a flap or window?     

asked by anonymous 25.12.2017 / 20:44

1 answer

1

One way to do this is to use iframe , below an example of how to do it (examples using jquery).

Create the iframe and put the appropriate style to make it invisible to the user:

let iframe = "<iframe id='iframe' src='https://pt.stackoverflow.com' style='display:none;visibility:hidden' />";
$("body").append(iframe);

To manipulate elements within the iframe, use .contents :

let page = $("#iframe").contents();

Now just look for the elements:

page.find("input");
    
03.01.2018 / 21:27