This repository has been archived by the owner on Oct 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pattern - run as background_script - expect to be webpacked or browsierfied in - feature telemetry relies on seeing the shield study in the scope. to be done: - storage of things - api to override? - prefs (as a permission for some addons, specific to each study) - know that uninstall happened to have finalize. - actually send telemetry - actually tag enviroment
- Loading branch information
Showing
9 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addon/background_scripts/index.js |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"description": "Adds a browser action icon to the toolbar.", | ||
"manifest_version": 2, | ||
"name": "Example Study", | ||
"version": "1.0", | ||
"browser_action": { | ||
"default_title": "Our Feature", | ||
"browser_style": true | ||
}, | ||
"background": { | ||
"scripts": [ | ||
"background_scripts/index.js" | ||
] | ||
}, | ||
"web_accessible_resources": [ | ||
"icons/kittens.jpg", | ||
"icons/puppies.jpg" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* global study */ | ||
|
||
|
||
|
||
function telemetry (data) { | ||
console.log("module telemetry:", data); | ||
study.telemetry(data); // we did window.study in the other file | ||
} | ||
|
||
let times = 0; | ||
function handleClick () { | ||
times += 1; | ||
console.log('got a click'); | ||
telemetry({"evt": "click", times: times}); | ||
} | ||
|
||
function init(branch) { | ||
browser.browserAction.setIcon({path: `icons/${branch}.png`}); | ||
browser.browserAction.setTitle({title: branch}); | ||
browser.browserAction.onClicked.addListener(handleClick); | ||
} | ||
|
||
exports.init = init; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
const shield = require("./shield-v4.js"); | ||
const feature = require("./feature/") | ||
const studyConfig = { | ||
name: self.id, | ||
days: 14, | ||
surveyUrls: { | ||
'end-of-study': 'http://example.com/some/url', | ||
'user-ended-study': 'http://example.com/some/url', | ||
'ineligible': null | ||
} | ||
} | ||
|
||
class ExampleStudy extends shield.ShieldStudy { | ||
chooseVariation () { | ||
return "kittens"; | ||
} | ||
} | ||
|
||
// put it up in global, because we are going to webpack | ||
let study = window.study = new ExampleStudy(studyConfig); | ||
|
||
function listenForTelemetryFromContent (request, sender, sendResponse) { | ||
console.log(request, sender, sendResponse); | ||
if (request.telemetry) { | ||
study.telemetry(request.data); | ||
} | ||
} | ||
|
||
browser.runtime.onMessage.addListener(listenForTelemetryFromContent); | ||
|
||
|
||
// this is the first time onlye | ||
if (study.isEligible()) { | ||
let variation = study.chooseVariation(); | ||
study.start(); | ||
feature.init(variation); | ||
telemetryOn(); | ||
} | ||
|
||
// other times we need to do other things | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "webpack-webextension", | ||
"version": "1.0.0", | ||
"description": "A minimal example of how to use npm modules from within a WebExtension.", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "webpack" | ||
}, | ||
"license": "MPL-2.0", | ||
"devDependencies": { | ||
"webpack": "^2.3.2" | ||
}, | ||
"dependencies": { | ||
"left-pad": "^1.1.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* shield under web extensions is just a library, | ||
MEANT to be webpacked/browserified */ | ||
|
||
//let study = new SubclassedStudy(config); | ||
|
||
class ShieldStudy { | ||
constructor (config) { | ||
this.config = config; | ||
} | ||
isEligible () { | ||
return true; | ||
} | ||
|
||
chooseVariation () { | ||
/* do some rng or deterministic magic */ | ||
} | ||
|
||
stored () { | ||
/*firstrun | ||
branchname*/ | ||
} | ||
|
||
isFirstRun () { | ||
// can check if we have any local storage? | ||
return true; | ||
} | ||
|
||
doOnce() { | ||
} | ||
|
||
cleanup () { | ||
console.log("cleaing up") | ||
} | ||
|
||
checkForExpiration () { | ||
return false | ||
} | ||
|
||
telemetry (...args) { | ||
console.log("telemtry sent:", ...args); | ||
} | ||
|
||
start () { | ||
console.log('starting up!') | ||
} | ||
|
||
die (reason) { | ||
switch (reason) { | ||
case "ineligible": | ||
case "uninstall": | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
go () { | ||
// try to do all the things? | ||
/* | ||
if this.isFirstRun | ||
checkEligible OR DIE | ||
pick and else a branch | ||
else | ||
revive a branch | ||
finally: | ||
mark the experiment branch | ||
start the clocks / timers | ||
return the branch | ||
and ask the feature to init it. // not our job | ||
*/ | ||
} | ||
} | ||
|
||
class PrefStudy extends ShieldStudy { | ||
constructor (config) { | ||
// does special thing with the prefs key | ||
} | ||
isEligible () { | ||
/*is the pref set*/ | ||
} | ||
} | ||
|
||
/* | ||
if (study.eligible()) { | ||
study.going().then(()=> | ||
yourfeature.startup(study.branch) | ||
) | ||
} | ||
"going" does this: | ||
spec stuff: | ||
- 1st startup | ||
- choose branch once | ||
- check eligible | ||
- Every startup | ||
- re-use branch | ||
- init the feature | ||
*/ | ||
|
||
exports.ShieldStudy = ShieldStudy; | ||
exports.PrefStudy = PrefStudy; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const path = require("path"); | ||
|
||
module.exports = { | ||
entry: { | ||
background_scripts: "./ourStudy.js", | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, "addon"), | ||
filename: "[name]/index.js" | ||
} | ||
}; |