-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from tshaddix/webext-support
Webext support
- Loading branch information
Showing
9 changed files
with
84 additions
and
41 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
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
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
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
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,14 @@ | ||
/** | ||
* Looks for a global browser api, first checking the chrome namespace and then | ||
* checking the browser namespace. If no appropriate namespace is present, this | ||
* function will throw an error. | ||
*/ | ||
export function getBrowserAPI() { | ||
const api = global.chrome || global.browser; | ||
|
||
if (!api) { | ||
throw new Error("Browser API is not present"); | ||
} | ||
|
||
return api; | ||
} |
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
File renamed without changes.
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,35 @@ | ||
|
||
import should from 'should'; | ||
|
||
import {getBrowserAPI} from "../src/util"; | ||
|
||
describe('#getBrowserAPI()', function () { | ||
it('should return the global chrome API if present', function () { | ||
global.chrome = { | ||
isChrome: true | ||
}; | ||
global.browser = undefined; | ||
|
||
const browserAPI = getBrowserAPI(); | ||
|
||
should(browserAPI).equals(global.chrome); | ||
}); | ||
|
||
it('should return the global browser API if chrome is not present', function () { | ||
global.chrome = undefined; | ||
global.browser = { | ||
isBrowser: true | ||
}; | ||
|
||
const browserAPI = getBrowserAPI(); | ||
|
||
should(browserAPI).equals(global.browser); | ||
}); | ||
|
||
it('should throw an error if neither the chrome or browser API is present', function () { | ||
global.chrome = undefined; | ||
global.browser = undefined; | ||
|
||
should.throws(() => getBrowserAPI()); | ||
}); | ||
}); |
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