Added FirefoxStrategy to interact with the Firefox extension for Postwoman
This commit is contained in:
parent
4b48d8a8c8
commit
5070d9fe95
2 changed files with 20 additions and 0 deletions
|
|
@ -4,6 +4,11 @@ import FirefoxStrategy from "./strategies/FirefoxStrategy";
|
|||
|
||||
|
||||
const runAppropriateStrategy = (req, store) => {
|
||||
// The firefox plugin injects a function to send requests through it
|
||||
// If that is available, then we can use the FirefoxStrategy
|
||||
if (window.firefoxExtSendRequest) {
|
||||
return FirefoxStrategy(req, store);
|
||||
}
|
||||
|
||||
if (store.state.postwoman.settings.PROXY_ENABLED) {
|
||||
return ProxyStrategy(req, store);
|
||||
|
|
|
|||
15
functions/strategies/FirefoxStrategy.js
Normal file
15
functions/strategies/FirefoxStrategy.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
const firefoxStrategy = (req, _store) => new Promise((resolve, reject) => {
|
||||
|
||||
const eventListener = (event) => {
|
||||
window.removeEventListener("firefoxExtSendRequestComplete", eventListener);
|
||||
|
||||
if (event.detail.error) reject(JSON.parse(event.detail.error));
|
||||
else resolve(JSON.parse(event.detail.response));
|
||||
};
|
||||
|
||||
window.addEventListener("firefoxExtSendRequestComplete", eventListener);
|
||||
|
||||
window.firefoxExtSendRequest(req);
|
||||
});
|
||||
|
||||
export default firefoxStrategy;
|
||||
Loading…
Reference in a new issue