S
S
sHARek2018-08-02 13:02:13
Google Chrome
sHARek, 2018-08-02 13:02:13

How to access DOM through extension and hide some element?

Good afternoon.
Learn how to make extensions for Google Chrome.
I decided to try to do something similar to AdBlock.
Let's say I get the URL of the current site in the active tab

chrome.tabs.query({active:true},function(tabsArray) {
  var tab = tabsArray[0];
  var tabUrl = tab.url;
  //var el = document.getElementById('url');
  //el.innerText = tabUrl;	
  //console.log(tabUrl);
  var e = document.getElementById('theme-header').style.display = 'none';
})

For example, on some page where I went and launched my extension, there is a block with id = "theme-header", I want to hide it.
How to access a "third party" page and set the display:none style?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2018-08-02
@sHARek

Content scripts are files that run in the context of web pages. By using the standard Document Object Model (DOM) , they are able to read details of the web pages the browser visits, make changes to them and pass information to their parent extension.

https://developer.chrome.com/extensions/content_scripts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question