From 8ae5dbc3750b9576e924d28b444e42288ce6c0af Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Sun, 19 Jan 2020 15:24:17 -0500 Subject: [PATCH 1/6] Fixed proxying through the firefox extension --- functions/strategies/FirefoxStrategy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/strategies/FirefoxStrategy.js b/functions/strategies/FirefoxStrategy.js index afe63498c..9160a27d3 100644 --- a/functions/strategies/FirefoxStrategy.js +++ b/functions/strategies/FirefoxStrategy.js @@ -6,7 +6,7 @@ const firefoxWithProxy = (req, { state }) => if (event.detail.error) { reject(JSON.parse(event.detail.error)); } else { - resolve(JSON.parse(event.detail.response)); + resolve(JSON.parse(event.detail.response).data); } }; From a235d38240881d561efa5b2816f381b452071f1d Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Tue, 21 Jan 2020 20:00:29 -0500 Subject: [PATCH 2/6] Added ChromeStrategy to interact with the Postwoman Chrome Extension --- functions/strategies/ChromeStrategy.js | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 functions/strategies/ChromeStrategy.js diff --git a/functions/strategies/ChromeStrategy.js b/functions/strategies/ChromeStrategy.js new file mode 100644 index 000000000..03c05ea0c --- /dev/null +++ b/functions/strategies/ChromeStrategy.js @@ -0,0 +1,56 @@ +const EXTENSION_ID = "amknoiejhlmhancpahfcfcfhllgkpbld"; + +// Check if the Chrome Extension is present +// The Chrome extension injects an empty span to help detection. +// Also check for the presence of window.chrome object to confirm smooth operations +export const hasChromeExtensionInstalled = () => { + return document.getElementById("chromePWExtensionDetect") !== null; +} + +const chromeWithoutProxy = (req, _store) => new Promise((resolve, reject) => { + chrome.runtime.sendMessage( + EXTENSION_ID, { + messageType: "send-req", + data: { + config: req + } + }, (message) => { + if (message.data.error) { + reject(message.data.error); + } else { + resolve(message.data.response); + } + } + ); +}); + +const chromeWithProxy = (req, { state }) => new Promise((resolve, reject) => { + chrome.runtime.sendMessage( + EXTENSION_ID, { + messageType: "send-req", + data: { + config: { + method: "post", + url: state.postwoman.settings.PROXY_URL || "https://postwoman.apollotv.xyz/", + data: req + } + } + }, (message) => { + if (message.data.error) { + reject(error); + } else { + resolve(message.data.response.data); + } + } + ) +}); + +const chromeStrategy = (req, store) => { + if (store.state.postwoman.settings.PROXY_ENABLED) { + return chromeWithProxy(req, store); + } else { + return chromeWithoutProxy(req, store); + } +} + +export default chromeStrategy; From 2d6d1b2d348875390e356ca5d5fc28a53e9783ce Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Tue, 21 Jan 2020 20:01:22 -0500 Subject: [PATCH 3/6] Added Chrome Strategy as a valid network strategy --- functions/network.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/functions/network.js b/functions/network.js index a2c885be5..4cb992b38 100644 --- a/functions/network.js +++ b/functions/network.js @@ -1,8 +1,13 @@ import AxiosStrategy from "./strategies/AxiosStrategy"; import FirefoxStrategy from "./strategies/FirefoxStrategy"; - +import ChromeStrategy, { hasChromeExtensionInstalled } from "~/functions/strategies/ChromeStrategy"; const runAppropriateStrategy = (req, store) => { + // Chrome Provides a chrome object for scripts to access + // Check its availability to say whether you are in Google Chrome + if (window.chrome && hasChromeExtensionInstalled()) { + return ChromeStrategy(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) { From 81654c35da09900b611e45185323d63abf183387 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Wed, 22 Jan 2020 12:38:17 -0500 Subject: [PATCH 4/6] Use relative imports Co-Authored-By: James George --- functions/network.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/network.js b/functions/network.js index 4cb992b38..f56c52676 100644 --- a/functions/network.js +++ b/functions/network.js @@ -1,6 +1,6 @@ import AxiosStrategy from "./strategies/AxiosStrategy"; import FirefoxStrategy from "./strategies/FirefoxStrategy"; -import ChromeStrategy, { hasChromeExtensionInstalled } from "~/functions/strategies/ChromeStrategy"; +import ChromeStrategy, { hasChromeExtensionInstalled } from "./strategies/ChromeStrategy"; const runAppropriateStrategy = (req, store) => { // Chrome Provides a chrome object for scripts to access From df21deddbaae3bf6a7a8b77521570433d20485b9 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Thu, 23 Jan 2020 09:15:59 +0530 Subject: [PATCH 5/6] :pencil2: Updated extensions link --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 529a1da32..193f0bbec 100644 --- a/README.md +++ b/README.md @@ -220,11 +220,13 @@ _**All `i18n` contributions are welcome to `i18n` [branch](https://github.com/li - **[Proxy β](https://github.com/postwoman-io/postwoman-proxy)** - A simple proxy server created for Postwoman - **[CLI β](https://github.com/postwoman-io/postwoman-cli)** - A CLI solution for Postwoman - - **[Browser Extensions](https://github.com/AndrewBastin/postwoman-firefox)** - Browser extensions that simplifies access to Postwoman + - **Browser Extensions** - Browser extensions that simplifies access to Postwoman - > [![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_16x16.png) **Firefox**](https://addons.mozilla.org/en-US/firefox/addon/postwoman)  |  ![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_16x16.png) **Chrome (coming soon)** + [![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_16x16.png) **Firefox**](https://addons.mozilla.org/en-US/firefox/addon/postwoman) ([GitHub](https://github.com/AndrewBastin/postwoman-firefox))  |  [![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_16x16.png) **Chrome**](https://chrome.google.com/webstore/detail/postwoman-extension-for-c/amknoiejhlmhancpahfcfcfhllgkpbld) ([GitHub](https://github.com/AndrewBastin/postwoman-chrome)) -_Add-ons are developed and maintained under **[Official Postwoman Organization](https://github.com/postwoman-io)**_ + >**Extensions fixes `CORS` issues.** + +_Add-ons are developed and maintained under **[Official Postwoman Organization](https://github.com/postwoman-io)**._ **To find out more, please check out [Postwoman Wiki](https://github.com/liyasthomas/postwoman/wiki).** From 8b7fd238d07b1f66867cf7e3e3cc5dd43bb31858 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Thu, 23 Jan 2020 11:03:22 +0530 Subject: [PATCH 6/6] :sparkles: Detech whether extension is already installed or not, if not, shoe install prompt toast --- layouts/default.vue | 51 ++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/layouts/default.vue b/layouts/default.vue index 4da707eec..4002a8875 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -470,27 +470,33 @@
- + + +
@@ -612,6 +618,7 @@