21

Checking out this sample extension linked by a page in the Chrome Extension center, I see they used

chrome.extension.onRequest.addListener(onRequest);

in the background.js page in order to listen to the contentscript.js and

  chrome.extension.sendRequest({}, function(response) {});

in the contentscript.js in order to talk to the background.js page.

But I can't find the documentation for these functions anywhere in the web and Google's Message Passing guide only mentions

chrome.extension.sendMessage(...)

to send, and

chrome.extension.onMessage.addListener(...)

to listen.

Which functions should I use? Is sendRequest/onRequest obsolete? Is the Google's dev guide still up-to-date?

Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
FRD
  • 2,254
  • 3
  • 19
  • 24

2 Answers2

20

It seems sendMessage is favored over sendRequest, which is to be deprecated: http://codereview.chromium.org/9965005/

Achal Dave
  • 4,079
  • 3
  • 26
  • 32
8

Also note the change in API path from

  • chrome.extension.onRequest
  • chrome.extension.sendRequest

to

  • chrome.runtime.onMessage
  • chrome.runtime.sendMessage

will save you getting frustrated over why e.g. chrome.extension.onMessage is not working!

peterthinking
  • 81
  • 1
  • 1