Added FirefoxStrategy to interact with the Firefox extension for Postwoman

This commit is contained in:
Andrew Bastin
2020-01-16 01:26:25 -05:00
parent 4b48d8a8c8
commit 5070d9fe95
2 changed files with 20 additions and 0 deletions

View File

@@ -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);

View 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;