Chrome Extension SDK Setup
Instructions for adding the OneSignal Chrome App SDK to your Chrome Extension
No longer being updated
Our Chrome App Extension is no longer being updated, however it is open source if you would like to contribute:
https://github.com/OneSignal/OneSignal-ChromeApp-SDK
Required For Setup
- OneSignal Account
- OneSignal App ID, available in Settings > Keys & IDs.
- A Google Server API Key. See Generating a Google Server API Key for details
1. Import OneSignal
1.1 Download the latest OneSignal Chrome App SDK.
1.2 Copy OneSignal.js
to your App/Extension project folder.
1.3 Continue to 2A if you have a Chrome App.
Or continue to 2B if you have a Chrome Extension.
2A. Add OneSignal to a Chrome App
2A.1 Open your manifest.json
and add OneSignal.js
before you own background.js.
"app": {
"background": {
"scripts": ["OneSignal.js", "background.js"]
}
},
Background HTML Page
If your manifest.json
contains a background page
instead of scripts
, then add OneSignal.js
to your background HTML page before your own background.js
.
2A.2 In your manifest.json
add the following 5 permissions to your permissions array.
"permissions": ["gcm", "storage", "notifications", "identity", "browser"],
2A.3 Continue to step 3.
2B. Add OneSignal to a Chrome Extension
2B.1 Open your manifest.json
and add OneSignal.js
before you own background.js
.
Create new blank background.js
file if you don't have a background script already.
"background": {
"persistent": false,
"scripts": ["OneSignal.js", "background.js"]
},
2B.2 In your manifest.json
, add the following permissions to your permissions array:
"permissions": ["gcm", "storage", "notifications", "identity"],
Permission Warnings
Adding some of these permissions, if they were not already present, may require users to re-allow your extension after an update. The list of new permissions that may cause this is available here.
Note that in Chrome 50, there is a bug that causes the "notifications" permission to cause this warning. You can find our more about this bug here.
3. Add Required Code
3.1 Open your background.js
file and add the following line outside of any function so it runs when your app/extension is loaded.
Replace appId
with your OneSignal App Id, and googleProjectNumber
with your own as well.
OneSignal.init({appId: "b2f7f966-d8cc-11e4-bed1-df8f05be55ba",
googleProjectNumber: "703322744261"});
Done! You should be all set to go with your Chrome App or Extension app.
Updated over 1 year ago