Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8965303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:46:38+00:00 2026-06-15T16:46:38+00:00

I’m creating a small google chrome extension for website, and I want to change

  • 0

I’m creating a small google chrome extension for website, and I want to change some html on particular pages.

The problem is that website load his content via ajax, and heavy use history.pushState API.
So, I added this thing to manifest:

"content_scripts": [
   {
     "matches": ["http://vk.com/friends"],
     "js": ["js/lib/jquery.min.js", "js/friends.js"],      
   },
 ]

Everything works fine when I’m opening page first time or reloading it.
But when I’m navigating between website pages, chrome don’t insert my scripts on “/friends” page. I think this happening because the URL actually don’t changing. They use history.pushState() and so, chrome can’t insert/rerun my script again.

Is there any solution for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:46:39+00:00Added an answer on June 15, 2026 at 4:46 pm

    You can add a window.onpopstate event in content script and listen for it, when an event fires you can re-run content script again.

    References

    a) extension.sendMessage()

    b) extension.onMessage().addListener

    c) tabs.executeScript()

    d) history.pushState()

    e) window.onpopstate

    Sample Demonstration:

    manifest.json

    Ensure content script injected URL and all API’s tabs have enough permission in manifest file

    {
        "name": "History Push state Demo",
        "version": "0.0.1",
        "manifest_version": 2,
        "description": "This demonstrates how push state works for chrome extension",
        "background":{
            "scripts":["background.js"]
        },
        "content_scripts": [{
            "matches": ["http://www.google.co.in/"],
            "js": ["content_scripts.js"]
         }],
        "permissions": ["tabs","http://www.google.co.in/"]
    }
    

    content_scripts.js

    Track for onpopstate event and send a request to background page for rerun of script

    window.onpopstate = function (event) {
        //Track for event changes here and 
        //send an intimation to background page to inject code again
        chrome.extension.sendMessage("Rerun script");
    };
    
    //Change History state to Images Page
    history.pushState({
        page: 1
    }, "title 1", "imghp?hl=en&tab=wi");
    

    background.js

    Track for request from content script and execute script to the current page

    //Look for Intimation from Content Script for rerun of Injection
    chrome.extension.onMessage.addListener(function (message, sender, callback) {
        // Look for Exact message
        if (message == "Rerun script") {
            //Inject script again to the current active tab
            chrome.tabs.executeScript({
                file: "rerunInjection.js"
            }, function () {
                console.log("Injection is Completed");
            });
        }
    });
    

    rerunInjection.js

    Some Trivial code

    console.log("Injected again");
    

    Output

    enter image description here

    Let me know if you need more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.