Ruth Barbour
Ruth Barbour

Reputation: 21

redirect to page.html after chrome extension installs

Here is my code, but it refuses to complile on the chrome developer dashboard. I have a page called my-page.php on the server

 {
   "content_scripts": [ {
      "all_frames": true,
      "js": [ "go.js" ],
      "matches": [ "\u003Call_urls\u003E" ]
   } ],
   "description": "blahhh",
   "icons": {
      "128": "icon128.png",
      "16": "icon16.png",
      "48": "icon48.png"
   },
   "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCdw+eIzaqEWfjrzJZ1TFO0/QVxWNdQEMvf4V6xdpZpTfIW3lOPVIJIvA6D4wyv6H+C8KAgbh58JEkqzgEC/1a+r4jGXhbvQk7Ybjj2CMVJBe6jF5Fz0ckPyTlPreFkT13PGwi72lljRZz7680VwY9jjPa7rsjV4hjTt2RRfi3UfwIDAQAB",
   "name": "my plugin",
      "background_page": "mypage.php",
      "permissions": [ "tabs", "*://*/*" ],
   "version": "1.3.0"
}

Upvotes: 2

Views: 2657

Answers (2)

Eric P
Eric P

Reputation: 4657

Chrome now has an onInstalled event. Most of you reading this probably know this already, but for those who (like me) search SO instead of reading the actual docs, check out:

https://developer.chrome.com/extensions/runtime.html#event-onInstalled

Upvotes: 5

Some Guy
Some Guy

Reputation: 16190

Your background page is to be packaged with the rest of your files. You can't have a background file that is on your server. It's throwing an error because you probably don't have a file called mypage.php in the folder for your extension. Learn about background pages.

There are no events that let your extension know when it has been installed, but a simple way to do it, would be to add code like this in your background file:

if(!localStorage.first){
    chrome.tabs.create({
       url : "http://whatever.com/welcome.html"
    });
    localStorage.first = "true";
}

This would work because the background file's code would be executed right after it was installed, and if localStorage.first didn't exist already, it would open the tab and set localStorage.first to true, so that it didn't open the tab the next time the background file's code was executed, i.e. when the browser was reopened.

Note that the tab will open if the user clears all localStorage as well. This was the only way I could think of, though.

Upvotes: 4

Related Questions