Activity Forums Salesforce® Discussions When developing a Chrome Extension, how to determine if it is running for the first time?

  • Abhinav

    Member
    April 14, 2016 at 8:08 am

    You can listen to the runtime.onInstalled event.

    Please refer here https://developer.chrome.com/extensions/faq#faq-lifecycle-events for more information.

  • shafali

    Member
    April 14, 2016 at 8:37 am

    Here is my json and js file that am using:

    manifest.json:
    {
    "name": "MyExtension",
    "version": "1.0",
    "description": "Bravo watch videos here!",
    "permissions": ["tabs", "http://*/*"],
    "content_scripts" : [{
    "matches" : [ "www.youtube.com/*"],
    "js" : ["shafali.js"]
    }]
    }

    shafali.js :

    function state() { console.log("State transit"); }
    var player = document.getElementById("videoPlayer");
    player.addEventListener("onStateChange", "state");
    console.log("Started!");

    I am trying to use the above code when developing my chrome extension which is to play youtube videos. But when I see the console the msg shows only 'Started!' not 'State transit' . What am I doing wrong?

  • Parul

    Member
    September 20, 2018 at 12:02 am

    function state() { console.log(“State transit”); }
    var player = document.getElementById(“videoPlayer”);
    player.addEventListener(“onStateChange”, “state”);
    console.log(“Started!”);

  • shariq

    Member
    September 20, 2018 at 8:09 pm

    Hi,

    I think you can use - runtime.onInstalled event.

    Hope this helps.

     

Log In to reply.

Popular Salesforce Blogs