Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

communicate between content script and bg

//background.js
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
  chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
    console.log(response.farewell);
  });
});

//content.js
chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    console.log(sender.tab ?
                "from a content script:" + sender.tab.url :
                "from the extension");
    if (request.greeting === "hello")
      sendResponse({farewell: "goodbye"});
  }
);
Comment

PREVIOUS NEXT
Code Example
Javascript :: repeated click onchange javascript 
Javascript :: board in javascript 
Javascript :: lowercase vs lower locale 
Javascript :: como hacer un contador de tiempo en javascript 
Javascript :: let result = 7 + 13 / 9 + 7; let result2 = 100 / 2 * 6; answer= result* result2; result = answer; final Result = result.toFixed(2); final Number = Number(final Result); console.log(finalNumber); 
Javascript :: The JavaScript call() Method 
Javascript :: CUSTOM_ELEMENTS_SCHEMA 
Javascript :: A Method In Class That Accesses A Property 
Javascript :: jQuery Misc Methods 
Javascript :: send a message in the first channel discord.js 
Javascript :: magnetic button vanilla js 
Javascript :: check for overlapping time javascript 
Javascript :: js filter out html 
Javascript :: mongodb instructions 
Javascript :: backbone view 
Javascript :: Backbone Add To Collection 
Javascript :: A Note on Jest & React 
Javascript :: react custum toogle 
Javascript :: jquery loop through model list 
Javascript :: Closure examples 
Javascript :: change your favicon in javascript 
Javascript :: moment add 
Javascript :: match all characters regex 
Javascript :: events node.js 
Javascript :: creating the find method javascript 
Javascript :: how to save data in javascript 
Javascript :: javascript undefined used with number, boolean or null 
Javascript :: javascript Arrow Function as an Expressio 
Javascript :: javascript Working of multiple yield Statements 
Javascript :: get max type value in solidity 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =