E
E
EatsFullLemons2014-10-23 13:46:51
Google Chrome
EatsFullLemons, 2014-10-23 13:46:51

I don’t understand how to force the chrome extension to run a js script on the site?

Greetings, I wrote a script that on my test page looks for certain codes inside a div, for example :smile: and replaces this phrase with the corresponding image. It remains to create an extension and make it run on vk.com/* - this way it will be possible to add emoticons to VK, even if only for those who have the extension. The script itself is not yet connected to the classes - VK chat. But first, I want to check to display alert('hello world') When entering any vk.com domain, to check if the script is connected. But I can't figure it out in google docks https://developer.chrome.com/extensions/content_scripts
Here is my manifest

{
    "manifest_version":2,
    
    "name":"...",
    "version":"0.0.0.1",
    "description":"....",
    "permissions":[
        "http://vk.com/*",
        "activeTab",
        "tabs",
        "http://*/"
    ],
    "browser_action": {
        "default_title": ....
    },
    "content_scripts": [{
        "matches": ["http://vk.com/*/"],
        "js": ["test.js"]
    }]
}

And here is actually test.js itself
var xml = new XMLHttpRequest(); 
xml.open('GET', "http://*/", true);
xml.send(null);
xml.onreadystatechange = function () {
    if(xml.state == 4) {
        if (xml.responseText){
            alert('Hello world');
        }
    }   
}

What is my problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mayorovp, 2014-10-23
@mayorovp

First, the last slash in matches is clearly redundant.
Secondly, VKontakte actively uses partial page loading from the server - so content scripts will only work when you enter VKontakte from another site or when you refresh the page - but they will not and should not work when you navigate inside VKontakte.
Third, you are sending an ajax request to a very strange address...
Fourth, don't forget about https://vk.com/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question