Load and subscribe on extension - javascript

I'm starting to create a simple chrome extension and one of the features I need is a notification system, so I'm using onesignal, in my script. I wish the user when installing the chrome extension to subscribe automaticlly, but it is not loading the object of onesignal which I can't figure out why. I'm saying this because no subscriptions is showing up after I install it.
My code:
manifest.json
{
"name": "My title",
"version": "0.0.1",
"manifest_version": 2,
"description": "some description",
"background": {
"scripts": [
"background.js","OneSignal.js"
],
"persistent": false
},
"browser_action": {
"default_title": "my extension"
},
"permissions": [
"https://*/*",
"http://*/*",
"tabs",
"gcm",
"notifications",
"storage",
"identity"
]
}
background.js:
OneSignal.init({appId: "dasdasd-b228-437d-bb8f-43asdasdb3", googleProjectNumber: "99999999"});
Am I missing something?

The problem is in the scripts order:
Solution:
...
background": {
"scripts": [
"OneSignal.js","background.js"
],
..

Related

Reading manifest: Error processing content_script: An unexpected property was found in the WebExtension manifest

I am trying to create a simple firefox addon that will modify page after XHR requests on pages. Unfortunately, after loading script, it shows error on about:debugging "Reading manifest: Error processing content_script: An unexpected property was found in the WebExtension manifest." It seems the content script then is not working at all.
Tried to change matches property to and inside content_scripts but it didn't work
{
"manifest_version": 2,
"name": "Some Name",
"version": "0.01a",
"applications": {
"gecko": {
"id": "some id"
}
},
"description": "Some Description",
"author": "Some Author",
"icons": {
"48": "icon.png",
"96": "icon.png"
},
"background": {
"scripts": ["jquery.min.js","declarations.js","bg.js"]
},
"content_script": [
{
"matches": ["*://somewebsite/folder/*"],
"js": ["jquery.min.js", "content.js"]
}
],
"permissions": [
"storage",
"*://somewebsite/folder/*",
"webRequest",
"webRequestBlocking"
]
}
What is wrong with the manifest.json? Where is error?
BTW, content.js:
console.log("CONTENT_SCRIPT");
function someFunction(request, sender, sendresponse) { somecode... }
browser.runtime.onMessage.addListener(someFunction);
The first is console.log and it doesn't show CONTENT_SCRIPT neither on debugging console nor the web console.
bg.js:
browser.runtime.sendMessage({
action: "timetodo",
result: requestDetails
});
The problem is that "content_script" key should be "content_scripts" (as it written in the documentation).
So use:
{
"manifest_version": 2,
"name": "Some Name",
"version": "0.01a",
"applications": {
"gecko": {
"id": "some id"
}
},
"description": "Some Description",
"author": "Some Author",
"icons": {
"48": "icon.png",
"96": "icon.png"
},
"background": {
"scripts": ["jquery.min.js","declarations.js","bg.js"]
},
"content_scripts": [
{
"matches": ["*://somewebsite/folder/*"],
"js": ["jquery.min.js", "content.js"]
}
],
"permissions": [
"storage",
"*://somewebsite/folder/*",
"webRequest",
"webRequestBlocking"
]
}

Google Chrome content_script not loading JS on matching URL

Even after searching a lot of topics in stack overflow, nothing helped me to fix this error...
I'm trying to create an extension, and for now there are simple codes in it, but unfortunately, the console is not logging 'Hello, world!' from the content_scripts file.
manifest.json
{
"manifest_version": 2,
"name": "Example",
"shortname": "exmpl",
"description": "__MSG_appDesc__",
"version": "0.0.1",
"default_locale": "en",
"author": "Mateus Akino",
"icons": {
"16": "i16x.png",
"48": "i48x.png",
"128": "i128x.png"
},
"homepage_url": "http://example.com/",
"browser_action": {
"default_icon": "i32x.png",
"default_popup": "popup.html"
},
"update_url": "http://example.com/update.xml",
"chrome_url_overrides": {
"newtab": "newtab.html"
},
"content_scripts": [{
"matches": ["*://*.youtube.com/*"],
"js": ["execute.js"],
"run_at": "document_end"
}],
"background": {
"scripts": ["background.js"]
},
"permissions": [
"activeTab", "tabs", "i18n", "management", "webNavigation", "<all_urls>"
]
}
execute.js
console.log("Hello, world!");
background.js
chrome.webNavigation.onHistoryStateUpdated.addListener(function (details) {
chrome.tabs.executeScript(null, {
file: "execute.js"
});
});
I fixed the problem, so I'm posting it here if someone else has the same issue.
Looks like the code was fine, the problem was the way I was loading the extension...
As I'm using 'Load unpacked extension', my manifest.json wasn't updating just by disabling and enabling it (neither by using Refresh extensions now).
So I removed the extension, loaded it again and it's working normally now.

Chrome extension Content Script not working

I built a Chrome Extension script that is supposed to run on Reddit.
My script:
console.log("hello world");
My manifest.json
{
"manifest_version": 2,
"name": "Name",
"description": "Desc",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png"
},
"content_scripts": [
{
"matches": [
"*://reddit.com/*"
],
"js": [
"contentscript.js"
],
"run_at": "document_end"
}
],
"permissions": [
"tabs", "*://reddit.com/*", "activeTab"
]
}
The script doesn't show up in the "Content Script" section in the chrome dev tools. Does anyone have an idea why my extension is not running?
"*://reddit.com/*" doesn't match a valid url, you should use "*://*.reddit.com/*"

Chrome extension popup not showing?

Well this is not showing the popup help!!!! When I run it the extension looks a bit white, without colour and when i click it the popup doesn't show up. Honestly I haven't got a clue!
{
"name": "Youtube",
"version": "0.0.1",
"manifest_version": 2,
"description": "Youtube",
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"default_locale": "en",
"page_action": {
"default_icon": "icons/icon19.png",
"default_title": "page action demo",
"default_popup": "files/popup.html"
},
"permissions": [
"bookmarks",
"chrome://favicon/",
"clipboardRead",
"clipboardWrite",
"contentSettings",
"contextMenus",
"cookies",
"fileBrowserHandler",
"tts",
"ttsEngine",
"history",
"idle",
"management",
"notifications",
"tabs",
"geolocation"
],
"content_scripts": [
{
"matches": [
"http://www.youtube.com*"
],
"js": [
"js/Youtube.js"
]
}
]
}
A page action needs to be "shown" for the button to do anything, i.e. you have to either call chrome.pageAction.show for a tab or use chrome.declarativeContent to show it.
Blame Google for crippling Page Actions so they are now unintuitive.
If you want an always-active button you need a Browser Action instead.

Chrome Keyboard shortcuts

I am trying to get a keyboard shortcut to work and at this point I am just testing to see that pressing the shortcut works. So currently what I have it do is send a message to the background page that it is working but the key press never registers. I was wondering how to address this issue.
manifest.json
{
"manifest_version": 2,
"name": "My Cool Extension",
"version": "0.3.1.5",
"description":"User can enter in wepage and press button to open webpage in new tab.",
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["jquery-2.1.4.min.js", "content.js"]
}
],
"browser_action": {
"default_icon": "arrow.png",
"default_popup":"popup.html"
},
"permissions": [
"tabs",
"storage"
],
"icons":{
"128":"arrow.png"
},
"commands": {
"openSavedTab": {
"suggested_key": {
"default": "Ctrl+Shift+Y",
"mac": "Command+Shift+Y"
},
"description": "Opens saved tab"
}
}
}
tab_shortcuts.js
chrome.commands.onCommand.addListener(function(command) {
chrome.tabs.update({}, function(tab) {
if (command == 'toggle-pin-tab')
chrome.extension.getBackgroundPage().console.log("Shortcut is functional");
alert("working");
});
});
Thank you wOxxOm for your help. You were right when you said the issue was with a conflicting extension with the same hotkey assigned. Once I disabled the extension my extension worked properly.

Categories

Resources