javascript - Why does the runtime of my Chrome extension content script not have any onMessage only connect and send message -


i've been struggling days on this, extension's content script seems missing permissions or something, i've searched through api docs , found nothing.

the messaging works if send message content page, not content page following code:

from background page:

var messagecallback = function (e) {     var nodemessage = json.parse(e.data);      switch (nodemessage.executiontype) {         case 0:             chrome.tabs.create({ url: nodemessage.url }, function (tab) {                  //injects injected.js not messages.js                 injectcode(tab.id);                  chrome.tabs.sendmessage(tab.id,nodemessage);             });         break; //some other switch cases... 

from content script:

chrome.runtime.onmessage.addlistener(function (message) {     console.log('message received');      var event = new customevent("foo_receive", {         detail: message,         bubbles: true     });      console.log('event sent');     document.dispatchevent(event); }); 

my manifest looks this:

{   "manifest_version": 2,    "name": "extesnion_name",   "short_name": "thing",   "description": "long sentence",   "version": "1.0.0",   "icons": { "16": "icon16.png",              "48": "icon48.png",              "128": "icon128.png" },   "permissions": ["background", "tabs", "<all_urls>" ],   "background": {     "scripts": ["background.js"],     "persistent": true   },   "content_scripts":[       {          "matches": ["<all_urls>"],          "js": ["messages.js"],       }   ],   "web_accessible_resources": ["injected.js"] } 

the following shows in chrome console:

content script:

enter image description here

and background page:

enter image description here

if chrome.runtime.onmessage undefined, see error message in console telling when running content script.

what's happening seeing limited version of chrome.runtime in console because accessing webpage context instead of content script context. see this answer access content script context console.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -