point the browser to the `extension/manifest.json` file.
This will enable the extension and will allow you to use the inspector to debug.
+
+### Testing on Chrome
+
+In order to test on chrome, first go to `chrome://extensions/`. Make sure
+`Developer mode` is enabled. Then click `Load Unpacked` and point the browser
+to the `extension` directory.
const internals = {
+ promisesSupported: !!(window.browser),
isInCallState: false,
icons: {
internals.isInCallState = true;
internals.setIcon('hangUp');
- const tabs = await browser.tabs.query({
- currentWindow: true,
- active: true
- });
+ console.log('setting tabs');
+ const activeTabs = await internals.getActiveTabs();
- internals.createAudioElement(browser.runtime.getURL('sounds/tada.wav'));
+ console.log(activeTabs[0].url); // placeholder while we connect backend.
+ internals.createAudioElement(internals.getRoot().runtime.getURL('sounds/tada.wav'));
},
hangUp() {
internals.isInCallState = false;
},
- createAudioElement(source) {
+ createAudioElement(source, type = 'audio/wav') {
const audioElement = document.createElement('audio');
audioElement.src = source;
audioElement.autoplay = 'autoplay';
+ audioElement.type = type;
document.querySelector('body').appendChild(audioElement);
},
setIcon(iconSet) {
- browser.browserAction.setIcon({
+ internals.getRoot().browserAction.setIcon({
path: internals.icons[iconSet]
});
- }
+ },
+
+ getRoot() {
+
+ return window.browser || window.chrome;
+ },
+
+ // Chrome doesn't yet implement the promise based tabs.query :'(
+
+ getActiveTabs() {
+
+ const query = {
+ currentWindow: true,
+ active: true
+ };
+
+ if (internals.promisesSupported) {
+ return internals.getRoot().tabs.query(query);
+ }
+
+ return new Promise((resolve, reject) => {
+
+ internals.getRoot().tabs.query(query, (tabs) => {
+
+ return resolve(tabs);
+ });
+ });
+ },
};
-browser.browserAction.onClicked.addListener(internals.onClick);
+internals.getRoot().browserAction.onClicked.addListener(internals.onClick);