Skip to content

Instantly share code, notes, and snippets.

@meandavejustice
Last active March 19, 2018 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meandavejustice/a2e025dde7da0f6e0a0b0d6630d61941 to your computer and use it in GitHub Desktop.
Save meandavejustice/a2e025dde7da0f6e0a0b0d6630d61941 to your computer and use it in GitHub Desktop.
Debugging options.html not showing up in testpilot webextension port

Issue

Options.html form elements (and OPTIONS button in about:addons view) not showing up.

Current Code

Code is structured as such:

  • webextension/options/options.html
  • webextension/options/options.js
  • webextension/manifest.json

Also made an edit to webpack.config.js (file attached) to ensure we are copying over the options/ directory to the build directory.

The steps I've taken

After checking to ensure I am followign the same patterns found on mdn and the implementation in the min vid addon. I started poking around at the actual built xpi, it appears that everything is in its proper place, however I'm a bit confused how the optionsURL field is added to install.rdf. It looks like this is done in the packaging process but I'm unsure, I tried to add a listing in the chrome.manifest like we are linking our iconURL(link), but that entry gets overwritten with "options/options.html" from manifest.json in the build.

Additionally Mdn says that webextension options should always take precedence over other types of prefs.

LINKS

link to bootstrapless-addon branch

{
"manifest_version": 2,
"name": "Test Pilot",
"author": "Les Orchard <me@lmorchard.com>",
"applications": {
"gecko": {
"id": "@testpilot-addon"
}
},
"version": "2.0.3",
"icons": {
"16": "icons/icon-16.png",
"32": "icons/icon-32.png",
"64": "icons/icon-64.png",
"96": "icons/icon-96.png"
},
"default_locale": "en_US",
"permissions": [
"notifications",
"storage",
"cookies",
"tabs",
"https://example.com/",
"https://testpilot.dev.mozaws.net/",
"https://testpilot-l10n.dev.mozaws.net/",
"https://testpilot.stage.mozaws.net/",
"https://testpilot.firefox.com/"
],
"background": {
"scripts": [
"background.js"
]
},
"browser_action": {
"default_title": "Firefox Test Pilot",
"browser_style": true,
"default_icon": "icons/icon.svg"
},
"options_ui": {
"page": "options/options.html",
"browser_style": true
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form>
<label for="environment">Environment:</label>
<select name="environment" id="environment">
<option value="https://example.com:8000" selected>Local</option>
<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>
</select>
<button type="submit">Save</button>
</form>
<script src="options.js"></script>
</body>
</html>
/* global browser */
function saveOptions(e) {
e.preventDefault();
browser.storage.local.set({
environment: {
name: document.getElementById("environment > option:changed").textContent,
baseUrl: document.getElementById("environment").value}
});
}
function restoreOptions() {
const getting = browser.storage.local.get("environment");
getting.then((result) => {
Array.from(document.getElementById("environment").options)
.forEach((o) => {
o.selected = (o.value === result.environment.value);
});
}, (err) => {
console.log(`Error: ${err}`);
});
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);
/*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/
/* eslint-disable import/no-extraneous-dependencies, global-require */
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const { exec, mkdir, cp } = require('shelljs');
const AfterBuildPlugin = require('./lib/webpack-after-build');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ThrowErrorPlugin = require('./lib/webpack-error');
const WATCH_MODE = process.argv.includes('--watch');
const baseConfig = {
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js'
},
module: {
loaders: [
{
test: /\.(js|jsx)/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
// Minimal babel transforms - Firefox supports many ES2015 features
babelrc: false,
presets: [],
plugins: []
}
}
]
},
plugins: [
new ThrowErrorPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': `"${process.env.NODE_ENV || 'dev'}"`
}),
// Package add-on when finished with build.
// TODO: Replace with sign-addon?
new AfterBuildPlugin(() => {
mkdir('-p', 'dist');
// 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';
if (fs.existsSync(buildPackagePath)) {
const frontendConfig = require('../frontend/config');
const locales = frontendConfig.AVAILABLE_LOCALES;
const env = Object.assign({}, process.env, {
SUPPORTED_LOCALES: locales
});
exec('node bin/update-version');
exec(
'node ./node_modules/.bin/pontoon-to-webext ' +
'--src ../locales --dest ./build/webextension/_locales',
{ env }
);
if (WATCH_MODE) {
exec('jpm post --addon-dir=build --post-url http://localhost:8888/');
} else {
const packageData = require(buildPackagePath);
exec('jpm xpi --addon-dir=build --dest-dir=dist');
cp('./dist/testpilot-addon.xpi', './addon.xpi');
cp(
`./dist/@testpilot-addon-${packageData.version}.update.rdf`,
'./update.rdf'
);
}
}
})
]
};
module.exports = [
// HACK: bootstrap.js needs to globally export startup & shutdown
Object.assign({}, baseConfig, {
entry: { bootstrap: './src/bootstrap.js' },
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js',
library: '{ startup, shutdown }',
libraryTarget: 'var'
}
}),
// The rest of the JS can get bundled like usual
Object.assign({}, baseConfig, {
entry: {
'webextension/background': './src/webextension/background.js'
},
plugins: [
new CopyWebpackPlugin([
{ from: 'LICENSE' },
{ from: './src/install.rdf' },
{ from: './package.json' },
{ from: './src/chrome.manifest' },
{ from: './src/webextension/manifest.json', to: './webextension/' },
{ from: './src/webextension/icons', to: './webextension/icons' },
{ from: './src/webextension/options', to: './webextension/options' }
])
].concat(baseConfig.plugins)
})
];
@meandavejustice
Copy link
Author

browser console addon install logging

1521481958053	addons.xpi	DEBUG	Calling bootstrap method shutdown on @testpilot-addon version 2.0.7-dev-cd27382
1521481958061	addons.xpi	DEBUG	Removing manifest for C:\Users\Dave Justice\AppData\Roaming\Mozilla\Firefox\Profiles\ho88n3g5.default\extensions\@testpilot-addon.xpi
1521481958072	addons.xpi	DEBUG	Disabling XPIState for @testpilot-addon
1521481958074	addons.xpi-utils	DEBUG	Updating active state for add-on @testpilot-addon to false
POST 
XHR 
https://incoming.telemetry.mozilla.org/submit/telemetry/015ee974-ac99-453c-ae1d-1ccebbafd2c0/testpilot/Firefox/61.0a1/nightly/20180319100039 
[HTTP/1.1 200 OK 367ms]
POST 
XHR 
https://ssl.google-analytics.com/collect 
[HTTP/2.0 200 OK 121ms]
OPTIONS 
XHR 
https://tiles.services.mozilla.com/v3/links/ping-centre 
[HTTP/1.1 200 OK 396ms]
POST 
XHR 
https://tiles.services.mozilla.com/v3/links/ping-centre 
[HTTP/1.1 200 OK 116ms]
1521481963223	addons.repository	DEBUG	cacheAddons: enabled true IDs ["@testpilot-addon"]
GET 
XHR 
https://services.addons.mozilla.org/api/v3/addons/search/ 
[HTTP/1.1 200 OK 440ms]
GET 
XHR 
https://services.addons.mozilla.org/api/v3/addons/compat-override/ 
[HTTP/1.1 200 OK 432ms]
[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIURI.hostPort]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: resource://gre/modules/PopupNotifications.jsm :: PopupNotifications_refreshPanel/< :: line 853"  data: no]  (unknown)
1521481964864	addons.xpi	DEBUG	Starting install of @testpilot-addon from file:///C:/Users/Dave%20Justice/Code/testpilot/addon/addon.xpi
1521481964875	addons.xpi	DEBUG	Addon @testpilot-addon will be installed as a packed xpi
1521481964877	addons.xpi	DEBUG	Loading bootstrap scope from C:\Users\Dave Justice\AppData\Roaming\Mozilla\Firefox\Profiles\ho88n3g5.default\extensions\@testpilot-addon.xpi
1521481964881	addons.xpi	WARN	Add-on @testpilot-addon is missing bootstrap method uninstall
1521481964888	addons.xpi-utils	DEBUG	Make addon app-profile:@testpilot-addon visible
1521481964890	addons.xpi	DEBUG	Updating XPIState for {"id":"@testpilot-addon","syncGUID":"{57a889d4-b250-448f-8b8f-fe80f64766f2}","location":"app-profile","version":"2.0.7-dev-cd27382","type":"extension","internalName":null,"updateURL":"https://testpilot.firefox.com/static/addon/update.rdf","updateKey":null,"optionsURL":"options/options.html","optionsType":5,"aboutURL":null,"defaultLocale":{"name":"Test Pilot","description":"Test Pilot is a privacy-sensitive user research program focused on getting new features into Firefox faster.","creator":"Mozilla (https://mozilla.org/)","homepageURL":"https://testpilot.firefox.com/"},"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"installDate":1521481739536,"updateDate":1521481963678,"applyBackgroundUpdates":1,"bootstrap":true,"path":"C:\\Users\\Dave Justice\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\ho88n3g5.default\\extensions\\@testpilot-addon.xpi","skinnable":false,"size":181795,"sourceURI":"file:///C:/Users/Dave%20Justice/Code/testpilot/addon/addon.xpi","releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"strictCompatibility":false,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"51.0","maxVersion":"*"}],"targetPlatforms":[],"signedState":0,"seen":true,"dependencies":[],"hasEmbeddedWebExtension":true,"userPermissions":null,"icons":{},"iconURL":"chrome://testpilot-addon-icons/content/icon-96.png","icon64URL":null,"blocklistState":0,"blocklistURL":null,"startupData":null}
1521481964891	addons.xpi	DEBUG	Updating XPIState for {"id":"@testpilot-addon","syncGUID":"{57a889d4-b250-448f-8b8f-fe80f64766f2}","location":"app-profile","version":"2.0.7-dev-cd27382","type":"extension","internalName":null,"updateURL":"https://testpilot.firefox.com/static/addon/update.rdf","updateKey":null,"optionsURL":"options/options.html","optionsType":5,"aboutURL":null,"defaultLocale":{"name":"Test Pilot","description":"Test Pilot is a privacy-sensitive user research program focused on getting new features into Firefox faster.","creator":"Mozilla (https://mozilla.org/)","homepageURL":"https://testpilot.firefox.com/"},"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"installDate":1521481739536,"updateDate":1521481739536,"applyBackgroundUpdates":1,"bootstrap":true,"path":"C:\\Users\\Dave Justice\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\ho88n3g5.default\\extensions\\@testpilot-addon.xpi","skinnable":false,"size":181795,"sourceURI":"file:///C:/Users/Dave%20Justice/Code/testpilot/addon/addon.xpi","releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"strictCompatibility":false,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"51.0","maxVersion":"*"}],"targetPlatforms":[],"signedState":0,"seen":true,"dependencies":[],"hasEmbeddedWebExtension":true,"userPermissions":null,"icons":{},"iconURL":"chrome://testpilot-addon-icons/content/icon-96.png","icon64URL":null,"blocklistState":0,"blocklistURL":null,"startupData":null}
1521481964892	addons.xpi	DEBUG	Loading bootstrap scope from C:\Users\Dave Justice\AppData\Roaming\Mozilla\Firefox\Profiles\ho88n3g5.default\extensions\@testpilot-addon.xpi
1521481964899	addons.xpi	WARN	Add-on @testpilot-addon is missing bootstrap method install
1521481964900	addons.xpi	DEBUG	Install of file:///C:/Users/Dave%20Justice/Code/testpilot/addon/addon.xpi completed.
1521481964909	addons.xpi	DEBUG	Registering manifest for C:\Users\Dave Justice\AppData\Roaming\Mozilla\Firefox\Profiles\ho88n3g5.default\extensions\@testpilot-addon.xpi
1521481964910	addons.xpi	DEBUG	Calling bootstrap method startup on @testpilot-addon version 2.0.7-dev-cd27382
1521481964910	addons.xpi	WARN	Exception running bootstrap method startup on @testpilot-addon: TypeError: undefined is not a function (resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///C:/Users/Dave%20Justice/AppData/Roaming/Mozilla/Firefox/Profiles/ho88n3g5.default/extensions/@testpilot-addon.xpi!/bootstrap.js:542:10) JS Stack trace: startup@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///C:/Users/Dave%20Justice/AppData/Roaming/Mozilla/Firefox/Profiles/ho88n3g5.default/extensions/@bootstrap.js:542:10
callBootstrapMethod@XPIProvider.jsm:4363:20
startInstall/<@XPIInstall.jsm:1812:13
async*startInstall@XPIInstall.jsm:1708:6
install@XPIInstall.jsm:1380:7
install@XPIInstall.jsm:2049:5
checkForBlockers@XPIInstall.jsm:1666:5
install@XPIInstall.jsm:1377:7
install@XPIInstall.jsm:2049:5
checkPrompt/<@XPIInstall.jsm:1641:7
async*checkPrompt@XPIInstall.jsm:1621:6
install@XPIInstall.jsm:1374:7
install@XPIInstall.jsm:2049:5
install@XPIInstall.jsm:2572:5
startInstall@AddonManager.jsm:1932:5
installAddonFromAOM@AddonManager.jsm:2037:5
installAddonFromAOM@AddonManager.jsm:3509:5
onDrop/<@extensions.js:3644:11
safeCall@AddonManager.jsm:177:5
makeSafe/<@AddonManager.jsm:192:25
promise callback*promiseOrCallback@AddonManager.jsm:218:3
getInstallForURL@AddonManager.jsm:3415:12
onDrop@extensions.js:3643:9
initialize/<@extensions.js:149:5
EventListener.handleEvent*initialize@extensions.js:148:3
EventListener.handleEvent*@extensions.js:98:1
1521481964912	addons.xpi	DEBUG	removeTemporaryFile: file:///C:/Users/Dave%20Justice/Code/testpilot/addon/addon.xpi does not own temp file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment