Added FirefoxStrategy to interact with the Firefox extension for Postwoman
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user