Run a specified function when the user opens a new tab in Chromium

pyon

I want to remove the most visited thumbnails from Chromium's “New Tab” page. After inspecting the contents of that page, I determined that the following line of JavaScript does the trick:

document.getElementById("most-visited").remove();

But I still have one remaining problem: How do make it so that this line runs automatically when I open a new tab? Presumably I have to wrap it in a function and register an event handler, but I've been unable to find more precise information.


EDIT:

It seems that Chromium explicitly prevents tampering with the “New Tab” page. I debugged Haibara Ai's solution by making the following changes:

  1. In manifest.json:

    "matches": [
        "*://*/*"
      ],
    
  2. In content.js:

    var mv = document.getElementById("most-visited");
    if (mv) mv.remove(); else window.alert("test");
    

And reloaded the extension. When I opened a New Tab, the thumbnails still appeared. Yet, when I refreshed a different page, a message box saying “test” was displayed.

Haibara Ai
  1. Use Content scripts. As for matching newtab url, see What is the URL of the google chrome new tab page and how to exclude it from manifest.json.

    manifest.json

    {
      "name": "Redesign",
      "version": "1.0",
      "manifest_version": 2,
      "content_scripts": [
        {
          "matches": [
            "*://*/_/chrome/newtab*"
          ],
          "js": [
            "content.js"
          ]
        }
      ]
    }
    

    content.js

    document.getElementById("most-visited").remove();
    
  2. Use Programmatic injection. You could listen to new tab opened event via chrome.tabs.onCreated, check the tab url and determine whether to call chrome.tabs.executeScript.

  3. Customize new tab page. You could also customize your own new tab page without the most visited part.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Run a specified function when the user opens a new tab in Chromium

From Dev

Tapestry - Persistent data is overridden when user opens a new tab

From Dev

JWT: how to handle GET requests when user opens a new tab?

From Dev

How to run a cancellable function when a new Tkinter window opens

From Dev

Detect if user opens link in new tab and redirect to new url

From Dev

xdg-open only opens a new tab in a new Chromium window despite passing it a URL

From Dev

New tab in chromium is empty

From Dev

fancybox opens in new tab

From Dev

How to disable chromium focus to new tab when clicking link?

From Dev

Yahoo Search opens when I open a new tab in Firefox

From Dev

Chromium "New Tab" page not loading

From Dev

Open link in new tab when user clicks

From Dev

How to run function on new tab from main tab? (Google Chrome)

From Dev

angularjs: trigger ng-click function when user right clicks and selects open in new tab

From Dev

I want to run a function when ever the form is clicked on taskbar and it opens

From Dev

terminal command to open new chromium tab

From Dev

terminal command to open new chromium tab

From Dev

What is the command to open a webpage in a new chromium tab?

From Dev

Pressing <Down> opens a new tab in Konsole

From Dev

Selenium - Clicking a link opens up a new tab

From Dev

jQuery .load() opens script in a new tab

From Dev

Mailto link in chrome opens new tab

From Dev

Pressing <Down> opens a new tab in Konsole

From Dev

Key combo that opens entered url in new tab

From Dev

Firefox opens a new tab instead of javascript code

From Dev

How to make this HTML code opens in a new tab?

From Dev

Google Calendar Shurtcut Opens Additional "New" Tab

From Dev

Selenium opens new tab after SendKeys

From Dev

Run Audio on new tab when a link is clicked - HTML

Related Related

  1. 1

    Run a specified function when the user opens a new tab in Chromium

  2. 2

    Tapestry - Persistent data is overridden when user opens a new tab

  3. 3

    JWT: how to handle GET requests when user opens a new tab?

  4. 4

    How to run a cancellable function when a new Tkinter window opens

  5. 5

    Detect if user opens link in new tab and redirect to new url

  6. 6

    xdg-open only opens a new tab in a new Chromium window despite passing it a URL

  7. 7

    New tab in chromium is empty

  8. 8

    fancybox opens in new tab

  9. 9

    How to disable chromium focus to new tab when clicking link?

  10. 10

    Yahoo Search opens when I open a new tab in Firefox

  11. 11

    Chromium "New Tab" page not loading

  12. 12

    Open link in new tab when user clicks

  13. 13

    How to run function on new tab from main tab? (Google Chrome)

  14. 14

    angularjs: trigger ng-click function when user right clicks and selects open in new tab

  15. 15

    I want to run a function when ever the form is clicked on taskbar and it opens

  16. 16

    terminal command to open new chromium tab

  17. 17

    terminal command to open new chromium tab

  18. 18

    What is the command to open a webpage in a new chromium tab?

  19. 19

    Pressing <Down> opens a new tab in Konsole

  20. 20

    Selenium - Clicking a link opens up a new tab

  21. 21

    jQuery .load() opens script in a new tab

  22. 22

    Mailto link in chrome opens new tab

  23. 23

    Pressing <Down> opens a new tab in Konsole

  24. 24

    Key combo that opens entered url in new tab

  25. 25

    Firefox opens a new tab instead of javascript code

  26. 26

    How to make this HTML code opens in a new tab?

  27. 27

    Google Calendar Shurtcut Opens Additional "New" Tab

  28. 28

    Selenium opens new tab after SendKeys

  29. 29

    Run Audio on new tab when a link is clicked - HTML

HotTag

Archive