Bug 1398974: Part 6 - Add content script messaging to webext talos add-on. r=mixedpuppy,jmaher
authorKris Maglione <maglione.k@gmail.com>
Mon, 11 Sep 2017 18:25:35 -0700
changeset 430128 59069fc4ad5150fbb002628a618e4fdb009f7b40
parent 430127 52e225228c3e1297d246bdb34863bcbc8c0c9653
child 430129 6ff73d0599c56ec91210cd1a936aa85e9597153e
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, jmaher
bugs1398974
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1398974: Part 6 - Add content script messaging to webext talos add-on. r=mixedpuppy,jmaher MozReview-Commit-ID: Edn7BnZoHvK
testing/talos/talos/webextensions/dummy/background.js
testing/talos/talos/webextensions/dummy/content.js
--- a/testing/talos/talos/webextensions/dummy/background.js
+++ b/testing/talos/talos/webextensions/dummy/background.js
@@ -32,27 +32,36 @@ browser.webRequest.onHeadersReceived.add
   ["blocking", "responseHeaders"]);
 
 browser.webRequest.onErrorOccurred.addListener(
   details => {
   },
   {urls: ["https://*/*", "http://*/*"]});
 
 
+browser.runtime.onMessage.addListener(msg => {
+  return Promise.resolve({code: "10-4", msg});
+});
+
+
 browser.tabs.onUpdated.addListener((tabId, changed, tab) => {
   if (changed.url) {
     browser.pageAction.show(tabId);
   }
   if (changed.title) {
     browser.pageAction.setTitle({tabId, title: `title: ${tab.title}`});
     browser.pageAction.setIcon({tabId, path: {16: "/icon.png"}});
 
     browser.browserAction.setTitle({tabId, title: `title: ${tab.title}`});
     browser.browserAction.setIcon({path: {16: "/icon.png"}});
   }
+
+  browser.tabs.sendMessage(tabId, {changed, tab}).catch(() => {
+    // Ignore tabs that don't have a listener yet.
+  });
 });
 
 browser.tabs.onActivated.addListener(({tabId, windowId}) => {
   browser.pageAction.show(tabId);
 });
 
 browser.tabs.onCreated.addListener(tab => {
   browser.pageAction.show(tab.id);
--- a/testing/talos/talos/webextensions/dummy/content.js
+++ b/testing/talos/talos/webextensions/dummy/content.js
@@ -1,3 +1,12 @@
 "use strict";
 
-// Empty content script
+/* eslint-env webextensions */
+
+browser.runtime.sendMessage({
+  msg: "Hello from content script",
+  url: location.href,
+});
+
+browser.runtime.onMessage.addListener(msg => {
+  return Promise.resolve({code: "10-4", msg});
+});