P
P
Perkovec2014-11-18 20:19:30
JavaScript
Perkovec, 2014-11-18 20:19:30

When you navigate to another page, does the chrome extension stop working?

I'm making an extension for chrome, which adds another button to the "Attach" tab when writing a VK post.
Here is my manifest:

{
    "manifest_version": 2,
    "name": "Chrome extension",
    "version": "0.1",
 
    "icons": {
        "128": "128x128.png"
    },
 
    "permissions": [
        "tabs",
        "http://vk.com/*",
        "https://vk.com/*"
    ],
 
    "content_scripts": [
    {
      "all_frames": true,
      "matches": ["http://vk.com/*","https://vk.com/*"],
      "css": ["style.css"],
      "js": ["jquery.js","script.js"],
      "run_at": "document_start"
    }],
    "web_accessible_resources": [ "img.png" ]
}

Here is a sample code from script.js
window.onload = function(){
  $( ".add_media_type_1_audio" ).after( "<a class='add_media_type_26_audio add_media_item activate_modal' name='code_window' style='background-image: url("+chrome.extension.getURL('img.png')+"); background-position: 3px 3px;'><nobr>Кнопка</nobr></a>" );
  // тут остальные действия с этой кнопкой
}

When you immediately enter a link to a group, then everything is displayed perfectly, but as soon as you go to any tab ("My page" for example) and through "My groups" go to the one we need, it ceases to be displayed. Well, sort of like that.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Taratin, 2014-11-18
@Perkovec

window.onload will only fire after the page is loaded. VK page changes through ajax and history api.
Use
https://github.com/kapetan/jquery-observe or https://github.com/megawac/MutationObserver.js or https://github.com/Polymer/MutationObservers
Some of them were buggy, but no longer remember which one. Unsubscribe later, which of this is working.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question