Bootstrapless addon #3456
Bootstrapless addon #3456
Conversation
- refs mozilla#3182
- fixes mozilla#3176
- options page is not showing up yet, I have a hunch that this may be because of the addon is still a bootstrap hyrid, something seems to be blocking the loading of the options.html page. Going to keep investigating, but wanted to commit to get these changes pushed to remote.
163f8fb
to
1207ff1
Compare
}); | ||
} | ||
|
||
async function setup() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the starting point for the webextension.
Here we:
- fetch or generate a clientUUID(used to daily metric ping)
- setupEnvironment(setup listener for changing of addon environement(local/dev/stage/prod)
- setup our browser action button
- populate resources (experiments and news feed)
- detect our installed test pilot addons and add listeners to keep that updated on install/uninstall events.
- setup our daily ping interval
addon/background.js
Outdated
}); | ||
} | ||
|
||
function submitPing(object, event, addons) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Telemetry and ping centre are no longer called in the new webextension. We're only using google analytics now.
@@ -0,0 +1,206 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where everything happens for the webextension. Most of what is in there was pulled from src/webextension/lib/{browserAction, storage}
and src/lib/pings
.
var manifestJSON = JSON.stringify(manifest, null, ' '); | ||
fs.writeFileSync(manifestFilename, manifestJSON); | ||
|
||
var installFilename = __dirname + '/../build/install.rdf'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is virtually the same except for generation of install.rdf
was removed.
addon/manifest.json
Outdated
@@ -16,6 +17,7 @@ | |||
}, | |||
"default_locale": "en_US", | |||
"permissions": [ | |||
"management", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used for tracking addon installs/uninstalls
@@ -0,0 +1,26 @@ | |||
/* global browser */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Environments came from src/webextension/lib/environments.js
. They are now part of the options page as we no longer have access to about:config
prefs.
@@ -1,108 +0,0 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer use frame scripts for detecting test pilot addon on certain mozilla properties
@@ -1,26 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap-removal
@@ -1,66 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now using the management
api to fetch addons and determine which txp addons are installed at the time of the daily ping.
@@ -1,30 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap-removal, sessionstore-windows-restored
was a hack to speed up startup for hybrid bootstrap embedded webextensions.
@@ -1,176 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap-removal, no longer provide metrics channel for experiments
@@ -1,87 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap-removal, this was a bridge for talking to the embedded webextension
@@ -1,63 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removal of frame scripts, see https://github.com/mozilla/testpilot/pull/3456/files#r178343655
@@ -1,100 +0,0 @@ | |||
// Shared metrics ping formatting & logic for bootstrap and webextension, with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ga ping snippet pulled for background.js
. Everything else removed.
@@ -1,53 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bootstrap-removal, no longer using prefs
@@ -1,126 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap-removal, no more telemetry
@@ -1,65 +0,0 @@ | |||
// Shared list of topics for PubSub usage in bootstrap and webextension |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap-removal, part of pubsub bridge to webextension. no longer needed
@@ -1,17 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log is commented out for development use in background.js
@@ -1,83 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap-removal, embedded webextension management and bridge
@@ -1,102 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost this whole file is now in background.js
@@ -1,36 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap-removal
@@ -1,28 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap-removal
@@ -1,148 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap-removal, daily-ping was written fresh using browser.alarms in background.js
@@ -1,23 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now in background.js
@@ -1,14 +0,0 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap-removal
@@ -1 +0,0 @@ | |||
// Global setup for all tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty file
// HACK: Only perform bundling if the second half of build has been | ||
// performed, but we still want to rebuild & post the first half on file | ||
// watching. | ||
const buildPackagePath = './build/package.json'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved into npm scripts
- fixes mozilla#3382 - fixes mozilla#3183 - fixes mozilla#3176 - fixes mozilla#3177 - fixes mozilla#3182 - fixes mozilla#3180 - fixes mozilla#3313
1207ff1
to
6951b1b
Compare
I seem to be having an issue with the update-version script and web-ext. It appears that npm is cacheing
I'm going to remove |
addon/background.js
Outdated
browser.management.onEnabled.addListener(setInstalledTxpAddons); | ||
browser.management.onDisabled.addListener(setInstalledTxpAddons); | ||
browser.management.onInstalled.addListener(setInstalledTxpAddons); | ||
browser.management.onUninstalled.addListener(setInstalledTxpAddons); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we only use installedTxpAddons
in the daily ping. It might be more polite to just run setInstalledTxpAddons
then. Not a blocker. Your call.
addon/background.js
Outdated
browser.storage.onChanged.addListener((changes) => { | ||
Object.keys(changes).forEach((k) => { | ||
if (k === "environment") { | ||
currentEnvironment = changes[k]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be changes[k].newValue
addon/background.js
Outdated
const delayInMinutes = 5; | ||
const periodInMinutes = 60 * 24; // daily | ||
|
||
browser.alarms.create("daily-ping", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this will fire after 5 minutes every time I restart the browser, which might be ok? (not my call) If we really only want at most one ping per day we should save a timestamp to storage so we can check it on startup.
addon/background.js
Outdated
log("fetchResources"); | ||
return Promise.all( | ||
Object.keys(resources).map(path => | ||
fetch(`${currentEnvironment.baseUrl}/api/${path}.json`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this indenting is hard to read
addon/background.js
Outdated
text: (newExperiments.length || newsUpdates.length) > 0 ? "!" : "" | ||
}); | ||
|
||
browser.browserAction.setBadgeText({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk why this is here twice. bad merge?
addon/options/options.html
Outdated
<option value="https://testpilot.dev.mozaws.net">Development</option> | ||
<option value="https://testpilot-l10n.dev.mozaws.net">L10n</option> | ||
<option value="https://testpilot.stage.mozaws.net">Stage</option> | ||
<option value="https://testpilot.firefox.com">Production</option> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since production is the default in background.js I think it should be the one initialized to selected here
addon/background.js
Outdated
const twoWeeksAgo = Date.now() - TWO_WEEKS; | ||
const newsUpdates = (news_updates || []).filter((u) => u.major) | ||
.filter((u) => new Date(u.published).getTime() >= twoWeeksAgo) | ||
.filter((u) => new Date(u.published).getTime() >= new Date(lastViewed)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: lastViewed
shouldn't need a Date wrapper
addon/background.js
Outdated
async function setup() { | ||
const data = await storage.get("clientUUID"); | ||
if (!data.clientUUID) { | ||
await storage.set({ clientUUID: clientUUID = uuidv4() }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your let clientUUID
above doesn't get initialized once it's already stored
addon/manifest.json
Outdated
@@ -16,6 +17,7 @@ | |||
}, | |||
"default_locale": "en_US", | |||
"permissions": [ | |||
"management", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs "alarms" permission
addon/background.js
Outdated
} | ||
|
||
const storage = browser.storage.local; | ||
const RESOURCE_UPDATE_INTERVAL = 10000; // 4 hours |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10000
isn't actually 4 hours ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh that was a testing mistake. forgot to change, thanks for catching that!
- remove unneccessary date wrapper - fix daily ping to test date before sending request - indent cleanup - change default in options.html to local - fix setting of environment from onchanged listener
addon/background.js
Outdated
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)); | ||
} | ||
|
||
function setInstalledTxpAddons() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it might be better to call this getInstalledTxpAddons
now
addon/background.js
Outdated
const ONE_DAY = 60 * 60 * 1000 * 24; /* ms */ | ||
const { lastPing } = await storage.get("lastPing"); | ||
if (initial || ((new Date) - lastPing) > ONE_DAY) { | ||
setInstalledTxpAddons().then((installedTxpAddons) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: await
instead of then
addon/background.js
Outdated
periodInMinutes | ||
}); | ||
|
||
browser.alarms.onAlarm.addListener((alarmInfo) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs async
on the callback
addon/background.js
Outdated
setupEnvironment(); | ||
setupBrowserAction(); | ||
await fetchResources(); | ||
setDailyPing(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should have await
for consistency
addon/background.js
Outdated
const { clientUUID } = await storage.get("clientUUID"); | ||
if (!clientUUID) { | ||
await storage.set({ clientUUID: uuidv4() }); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putting all the clientUUID code in setDailyPing
is more cohesive
addon/background.js
Outdated
if (initial || ((new Date) - lastPing) > ONE_DAY) { | ||
setInstalledTxpAddons().then((installedTxpAddons) => { | ||
const { clientUUID } = await storage.get({ clientUUID: uuidv4() }); | ||
submitPing(alarmInfo.name, "installed-addons", installedTxpAddons, clientUUID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lastPing
needs to be set after one is sent
addon/background.js
Outdated
if (!lastPing) { | ||
initial = true; | ||
await storage.set({ lastPing: Date.now()}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove initial
and skip this if we default lastPing
to yesterday
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woah clever 👍
addon/background.js
Outdated
|
||
async function sendPingOnAlarm(alarmInfo) { | ||
if (alarmInfo.name === "daily-ping") { | ||
const { lastPing } = await storage.get("lastPing"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking more along the lines of storage.get({ lastPing: Date.now() - ONE_DAY })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this would ever return successfully 🤔
addon/background.js
Outdated
} | ||
} | ||
}); | ||
browser.alarms.onAlarm.addListener(sendPingOnAlarm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
Codecov Report
@@ Coverage Diff @@
## master #3456 +/- ##
=======================================
Coverage 83.48% 83.48%
=======================================
Files 113 113
Lines 3172 3172
=======================================
Hits 2648 2648
Misses 524 524 Continue to review full report at Codecov.
|
Rewrite of addon as webextension
Functionality:
Structure:
Issues: