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

Asked

Viewed 1,142 times

4

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

But I need this to happen in background without the page being explicitly in the user’s browser, that is, I want to manipulate a page without opening it in a tab or window?

  • You have to learn to develop extensions for the Chrome browser preferably. On google there are several tutorials, examples, etc.

  • Which extension link does this?

1 answer

1


One of the ways to do this is by using the iframe, below an example of how to do (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://answall.com' style='display:none;visibility:hidden' />";
$("body").append(iframe);

To handle elements within the iframe, use the .contents:

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

Now just search for the elements:

page.find("input");
  • I think that’s not it, the question seems to speak of manipulating the document itself, not the content of another frame.

  • @bfavaretto Ah, maybe I didn’t explain my problem well in the question, but it solved it. Feel free to edit it or give me tips on how to improve it.

  • Hahaha, I didn’t see that the question was yours.

  • But I still don’t think you understand your question hahaha.

  • Francisco I think what @bfavaretto means is that his answer only explains the part of how to manipulate the content via iframe, but it doesn’t show an example of this in an extension and being an extension may need to apply perhaps some permission that is needed. I will try to formulate the answer between today and tomorrow, in case I will provide an example with JS even, but with jQuery will only change a few lines

  • @Guilhermenascimentop. I think the question is not clear. I have reread several times and still do not understand what he wants to do, even with the answer.

  • @bfavaretto was I who edited, I could not explain myself better, I only really understood the problem because I talked to the AP, the basic is this, "how to open and manipulate a page without it needing to be open in a tab or window", can you understand?

  • @Guilhermenascimentop. I have now read the original version and understood it a little better.

  • 1

    Yes, I understood what he really wants to do only after reading the original version. Now his edition is also clearer to me. @Guilh

  • @Please take to meta the question of the technical problem of using the tags and why you think it is wrong, stop asking the AP. There you will receive guidance or perhaps even prove your point. It is not my thinking, it is that you seem to be making confusion and if you seem to have confused it is likely that you do not dominate, there is no harm in this, so please stop Flood, have a technical point of view on the subject and use of tags? Great! Put in the goal and settle there with the general community.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.