Skip to content

Instantly share code, notes, and snippets.

@Gozala
Created June 16, 2018 01:00
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 Gozala/c9614fe7a482902f00c937add70c421f to your computer and use it in GitHub Desktop.
Save Gozala/c9614fe7a482902f00c937add70c421f to your computer and use it in GitHub Desktop.
Pretty WebExtension APIs
this.MyAPI = class extends ExtensionAPI {
getAPI(context) {
const sandbox = Cu.Sandbox(context.cloneScope, {
sameZoneAs: context.cloneScope,
wantComponents: false,
wantXrays: false
})
const init = Cu.evalInSandbox(function() {
class MyThing {
constructor(id) {
this.id = id
}
open() {
return this
}
close() {
return this
}
[Symbol.iterator] {
throw Error("Not Implemented")
}
}
return {MyThing}
}, sandbox)
const api = init()
return {
MyAPI: {
createMyThing(options) {
return new api.MyThing()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment