Re: I have to refresh the web page to see my chrome injection successfully done

62 views
Skip to first unread message
Message has been deleted

wOxxOm

unread,
Jan 31, 2023, 9:35:34 AM1/31/23
to Chromium Extensions, ilg...@gmail.com
It's because the content scripts run only when the page environment is created, not just changed inside.
It's a modern web site (SPA) that updates the address bar programmatically as well as the contents of the page.
  • You can detect these changes by using MutationObserver.
  • A better solution might be to simply hide the element by selector via CSS instead of JS: https://stackoverflow.com/a/14411446

On Tuesday, January 31, 2023 at 3:08:54 PM UTC+3 ilg...@gmail.com wrote:
Hi folks,

I have a problem with my simple chrome extension project.
In my content.js file, I am removing a "div" tag with classname "1Lk-Z" from a specific web page.

$("._1Lk-Z").remove();

But the problem is, when I navigate in the web site (for example by clicking back button of the browser or just simply click home page) and then go back this specific page again, it seems the div tag is not removed.. But after refreshing the page, the div tag is removed again without any problem..

Any idea what is wrong with my implementation?

Thanks.



Message has been deleted

wOxxOm

unread,
Jan 31, 2023, 11:23:38 AM1/31/23
to Chromium Extensions, ilg...@gmail.com, wOxxOm
There are thousands of examples for MutationObserver, really.
Anyway, here's a third option: the new Navigation API: https://developer.chrome.com/docs/web-platform/navigation-api/#intercepting

On Tuesday, January 31, 2023 at 7:14:46 PM UTC+3 ilg...@gmail.com wrote:
I couldn't find any example using MutationObserver.
I managed to handle back and forward clicks (popstate) navigations but still couldn't find any solution for programmatically changed navigations

31 Ocak 2023 Salı tarihinde saat 17:35:34 UTC+3 itibarıyla wOxxOm şunları yazdı:
Reply all
Reply to author
Forward
0 new messages