From a064cfef8d3481596de8fc9c12398ca505c90dfe Mon Sep 17 00:00:00 2001 From: niloy Date: Sun, 19 Jun 2022 03:22:38 +0200 Subject: [PATCH 1/4] :bug: Remove polyfill script from manifest --- firefox/manifest.json | 1 - 1 file changed, 1 deletion(-) diff --git a/firefox/manifest.json b/firefox/manifest.json index 25ec7ff..37d3f0a 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -14,7 +14,6 @@ }, "background": { "scripts": [ - "build/browser-polyfill.js", "build/background.js" ], "persistent": false From 03e44bf53898fdc3f873143048cc4e72db471b32 Mon Sep 17 00:00:00 2001 From: niloy Date: Sun, 19 Jun 2022 04:09:28 +0200 Subject: [PATCH 2/4] :bug: Fix browserAction api undefined issue --- .gitignore | 2 ++ src/Browser/Background.ts | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2c4ff8a..58a7a17 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ node_modules chrome/build firefox/build chrome.pem +extension/.chrome +extension/.firefox diff --git a/src/Browser/Background.ts b/src/Browser/Background.ts index cc91327..6da0716 100644 --- a/src/Browser/Background.ts +++ b/src/Browser/Background.ts @@ -1,5 +1,5 @@ import { defer } from 'lodash' -import browser from 'webextension-polyfill' +import browser, { browserAction } from 'webextension-polyfill' type Connection = Map @@ -51,7 +51,10 @@ const tabRemovalListener = () => { }) } -browser.browserAction.onClicked.addListener(e => { +// For cross-browser support +const action = browser.browserAction || browser.action + +action.onClicked.addListener(e => { console.debug('action.onClicked', e) browser.tabs From 6fa28d0dd6a05a7bec38ac6855d8c2c96e44797b Mon Sep 17 00:00:00 2001 From: niloy Date: Sun, 19 Jun 2022 06:02:25 +0200 Subject: [PATCH 3/4] :zap: Add background script to redirect to new tab --- firefox/manifest.json | 3 ++- src/Browser/Background.ts | 17 +++++++++++++++++ src/Pages/Panel/Navigation.tsx | 22 ++++++---------------- src/Pages/Panel/Sponsor/SponsorHero.tsx | 10 +++------- src/Utils/BackgroundEvents.ts | 9 +++++++++ 5 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 src/Utils/BackgroundEvents.ts diff --git a/firefox/manifest.json b/firefox/manifest.json index 37d3f0a..b4429c3 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -32,7 +32,8 @@ ], "permissions": [ "https://api.github.com/*", - "https://www.google-analytics.com/*" + "https://www.google-analytics.com/*", + "tabs" ], "content_security_policy": "script-src 'self'; object-src 'self'", "web_accessible_resources": [ diff --git a/src/Browser/Background.ts b/src/Browser/Background.ts index 6da0716..9219711 100644 --- a/src/Browser/Background.ts +++ b/src/Browser/Background.ts @@ -116,6 +116,23 @@ const contentListener = () => { }) } +const tabListener = () => { + const tabEvent = { + 'create-tab': request => + browser.tabs + .create({ + url: request.data.url, + }) + .catch(console.error), + } + chrome.runtime.onMessage.addListener(function (request, sender) { + if (request.source !== 'meteor-devtools-evolved') return null + + tabEvent[request.eventType]?.(request) + }) +} + panelListener() tabRemovalListener() contentListener() +tabListener() diff --git a/src/Pages/Panel/Navigation.tsx b/src/Pages/Panel/Navigation.tsx index 319edfb..2555f44 100644 --- a/src/Pages/Panel/Navigation.tsx +++ b/src/Pages/Panel/Navigation.tsx @@ -8,6 +8,7 @@ import { Tag } from '@blueprintjs/core' import { isNumber } from 'lodash' import { useAnalytics } from '@/Utils/Hooks/useAnalytics' import browser from 'webextension-polyfill' +import { openTab } from '@/Utils/BackgroundEvents' export const Navigation: FunctionComponent = observer(() => { const panelStore = usePanelStore() @@ -64,11 +65,9 @@ export const Navigation: FunctionComponent = observer(() => { key: 'community', content: '👥 Community', handler: () => { - browser.tabs - .create({ - url: 'https://join.slack.com/t/meteor-community/shared_invite/zt-a9lwcfb7-~UwR3Ng6whEqRxcP5rORZw', - }) - .catch(console.error) + openTab( + 'https://join.slack.com/t/meteor-community/shared_invite/zt-a9lwcfb7-~UwR3Ng6whEqRxcP5rORZw', + ) analytics?.event('navigation', 'click', { label: 'community' }) }, @@ -105,12 +104,7 @@ export const Navigation: FunctionComponent = observer(() => { ), handler: () => { - browser.tabs - .create({ - url: repositoryData.html_url.concat('/issues'), - }) - .catch(console.error) - + openTab(repositoryData.html_url.concat('/issues')) analytics?.event('navigation', 'click', { label: 'feedback' }) }, shine: true, @@ -130,11 +124,7 @@ export const Navigation: FunctionComponent = observer(() => { ), shine: true, handler: () => { - browser.tabs - .create({ - url: repositoryData.html_url.concat('/stargazers'), - }) - .catch(console.error) + openTab(repositoryData.html_url.concat('/stargazers')) analytics?.event('navigation', 'click', { label: 'star' }) }, diff --git a/src/Pages/Panel/Sponsor/SponsorHero.tsx b/src/Pages/Panel/Sponsor/SponsorHero.tsx index 1541613..c0641ac 100644 --- a/src/Pages/Panel/Sponsor/SponsorHero.tsx +++ b/src/Pages/Panel/Sponsor/SponsorHero.tsx @@ -2,7 +2,7 @@ import React, { FC } from 'react' import { StringUtils } from '@/Utils/StringUtils' import { AppToaster } from '@/AppToaster' import MeteorCloudLogo from '@/Assets/meteor-cloud-logo.png' -import browser from 'webextension-polyfill' +import { openTab } from '@/Utils/BackgroundEvents' import '@/Assets/meteor-shower.jpg' @@ -77,9 +77,7 @@ export const SponsorHero: FC = () => { diff --git a/src/Utils/BackgroundEvents.ts b/src/Utils/BackgroundEvents.ts new file mode 100644 index 0000000..4fded8c --- /dev/null +++ b/src/Utils/BackgroundEvents.ts @@ -0,0 +1,9 @@ +import browser from 'webextension-polyfill' + +export const openTab = (url: string): void => { + browser.runtime.sendMessage({ + source: 'meteor-devtools-evolved', + eventType: 'create-tab', + data: { url: url }, + }) +} From ff9ae83b06c0303fb07c374dcf10ca80b6d65ad8 Mon Sep 17 00:00:00 2001 From: niloy Date: Mon, 20 Jun 2022 23:06:42 +0200 Subject: [PATCH 4/4] :bug: Fix firefox manifest --- firefox/manifest.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firefox/manifest.json b/firefox/manifest.json index b4429c3..d998d79 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -14,7 +14,7 @@ }, "background": { "scripts": [ - "build/background.js" + ".dist/background.js" ], "persistent": false }, @@ -24,7 +24,7 @@ "" ], "js": [ - "build/content.js" + ".dist/content.js" ], "run_at": "document_start", "all_frames": true @@ -37,7 +37,7 @@ ], "content_security_policy": "script-src 'self'; object-src 'self'", "web_accessible_resources": [ - "/build/inject.js" + "/.dist/inject.js" ], "devtools_page": "devtools.html" }