"No matching message handler" error when tabs.update().then(tabs.executeScript())




WebExtensions: Frontend
7 months ago
4 months ago


(Reporter: bibicron, Unassigned)


55 Branch

Firefox Tracking Flags

(firefox57 fix-optional)


(Whiteboard: [tabs])



7 months ago
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0
Build ID: 20170824053622

Steps to reproduce:

This could be related to Bug 1254003. Except that that bug manifested when tabs.create().then(tabs.executeScript()). Probably the fix is the same.

The error happens in the background script of an add-on. After the user clicks on the context menu, a new page will be displayed. The new page will be generated by a content script injected in a blank page. The new page can optionally open in:
- a new tab: tabs.create("about:blank").then(tabs.executeScript())
- the current tab: tabs.update("about:blank").then(tabs.executeScript())

Actual results:

In the first case (tabs.create) the code is executed correctly. In the second case (tabs.update) the code is just sometime executed correctly. When it fails, the Promise returned by the executeScript(), will be rejected with error "Error: No matching message handler".

Expected results:

The code should execute.


7 months ago
Component: Untriaged → WebExtensions: Frontend
Product: Firefox → Toolkit

Comment 1

7 months ago
The bug can be confirmed by the following code. The code can be run in a debug console of any add-on. The result should be "ok", not "fail: Error: No matching message handler";

var tabId = -1;
	function( tab_id, changeInfo, tab1 ) {
		if( tabId != -1 && tab_id == tabId && changeInfo.status == "complete" ) {
			tabId = -1;
			browser.tabs.update( tab_id, { url: "about:blank" } ).then(
				function( tab2 ) {
					browser.tabs.executeScript( tab2.id, { code: "alert(123);", matchAboutBlank: true } ).then(
						function() { console.log( "ok" ); },
						function( e ) { console.log( "fail: " + e ); }
browser.tabs.create( { url: "http://www.google.com" } ).then( 
	function( tab ) {
		tabId = tab.id;

Comment 2

7 months ago
The previous code will succeed if you replace:
    browser.tabs.update( tab_id, { url: "about:blank" } )
    browser.tabs.create( { url: "about:blank" } )


6 months ago
status-firefox57: --- → fix-optional
Priority: -- → P3
Whiteboard: [tabs]

Comment 3

5 months ago
I'm running into the same issue just in the success handler of `browser.windows.create`

    incognito: true,
    url: "https://www.mozilla.org/fr/privacy/firefox/",
    state: "minimized",
    type: "detached_panel"
}).then((window) => {
    let tab = window.tabs[0];
    browser.tabs.executeScript(tab.id, {
        code: "alert('I am alert')"
    }).then(() => {
        console.log("I was alerted")
    }).catch(() => {
        console.error("I failed")


Even adding a `browser.tabs.get(tab.id)` and executing a script in it doesn't work.

The firefox version I use is 58.0a1 (2017-10-20) (64-bit)

Comment 4

4 months ago
Same issue here.

It turns out that this problem happens when the tab still has status "loading". tabs.executeScript() parameter runAt defaults to "document_idle" (execute when everything is loaded) but this does not work (even when setting this property explicitly).

In my case, the problem is timing related and hard to reproduce as it does not happen every time. I was unable to reproduce it with Firefox Developer Edition, only with standard Firefox 57.

My workaround consists of waiting for the tab to get status "complete" before executing tabs.executeScript().

// create window and get its tab
  if(tab.status=="loading") {
    return new Promise((resolve, reject) => {
      var timer = setTimeout(()=>{
        reject(new Error("Tab did not complete"));
      function onUpdated(tabId,changeInfo,_tab) {
        if(tabId == tab.id && _tab.status=="complete") {
  } else 
    return tab;
// it's now safe to call tabs.executeScript
You need to log in before you can comment on or make changes to this bug.