'My chrome extension doesn't run at first time

"content_scripts": [
  {
    "matches": ["*://*.example.com/page2"],
    "js": ["contentScript.js"],
    "run_at": "document_idle"
  }
]

Well, the home page is "example.com/page1" that home page has a link <a href="/page2"></a> when I click at that link I would expected that my contentScript.js was injected at the page, but it doesn't happen, for that happens I need to refresh the page, only then contentScript.js works.

When I put at adress bar "example.com/page2" and search the contentScript.js works perfectly, but if I try to acess the page2 from the link that have at page1 it doesn't work, so I need to refresh the page.

I dont want to need refresh the page everytime. How do I fix it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source