Skip to content

Commit

Permalink
🔥 Add manifest v2 for firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
nilooy committed Jun 18, 2022
1 parent 7bd8f37 commit a31114c
Show file tree
Hide file tree
Showing 24 changed files with 168 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
chrome/builds
firefox/builds
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.idea
node_modules
chrome/build
firefox/build
chrome.pem
15 changes: 15 additions & 0 deletions firefox/devtools-panel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html data-theme="corporate">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
/>
<title>Panel</title>
</head>
<body>
<div id="panel" class="bp3-dark"></div>
<script src="/build/bundle.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions firefox/devtools.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
/>
<title>Developer Tools</title>
</head>
<body>
<!-- The sole purpose of this file is to load the JavaScript file as Chrome does not render it -->

<script src="/build/devtools.js"></script>
</body>
</html>
Binary file added firefox/icons/meteor-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/meteor-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/meteor-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/meteor-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/meteor-64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions firefox/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"manifest_version": 2,
"name": "Meteor DevTools Evolved",
"description": "The Meteor framework development tool belt, evolved.",
"version": "1.6",
"author": "Leonardo Venturini",
"icons": {
"16": "icons/meteor-16.png",
"48": "icons/meteor-48.png",
"128": "icons/meteor-128.png"
},
"browser_action": {
"default_title": "Meteor"
},
"background": {
"scripts": [
"build/browser-polyfill.js",
"build/background.js"
],
"persistent": false
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"build/content.js"
],
"run_at": "document_start",
"all_frames": true
}
],
"permissions": [
"https://api.github.com/*",
"https://www.google-analytics.com/*"
],
"content_security_policy": "script-src 'self'; object-src 'self'",
"web_accessible_resources": [
"/build/inject.js"
],
"devtools_page": "devtools.html"
}
15 changes: 15 additions & 0 deletions firefox/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
/>
<title>Options</title>
</head>
<body>
<div id="options" class="bp3-dark"></div>
<script src="/build/bundle.js"></script>
</body>
</html>
15 changes: 15 additions & 0 deletions firefox/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
/>
<title>Popup</title>
</head>
<body>
<div id="popup" class="bp3-dark"></div>
<script src="/build/bundle.js"></script>
</body>
</html>
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
],
"scripts": {
"devapp": "cd devapp && npm run start",
"build": "webpack --config webpack/chrome.prod.js"
"build:chrome": "webpack --config webpack/chrome.prod.js",
"build:firefox": "webpack --config webpack/firefox.prod.js",
"lint": "eslint ."
},
"author": "Leonardo Venturini",
"license": "MIT",
Expand Down Expand Up @@ -76,5 +78,9 @@
"volta": {
"node": "14.19.3",
"yarn": "1.22.18"
},
"devDependencies": {
"@types/webextension-polyfill": "^0.9.0",
"webextension-polyfill": "^0.9.0"
}
}
11 changes: 6 additions & 5 deletions src/Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import prettyBytes from 'pretty-bytes'
import { PanelStore } from '@/Stores/PanelStore'
import { DateTime } from 'luxon'
import { StringUtils } from '@/Utils/StringUtils'
import browser from 'webextension-polyfill'

export const syncSubscriptions = () =>
Bridge.sendContentMessage({
Expand Down Expand Up @@ -43,21 +44,21 @@ export const Bridge = new (class {
source: 'meteor-devtools-evolved',
}

if (chrome && chrome.devtools) {
chrome.devtools.inspectedWindow.eval(
if (browser && browser.devtools) {
browser.devtools.inspectedWindow.eval(
`__meteor_devtools_evolved_receiveMessage(${JSON.stringify(payload)})`,
)
}
}

chrome() {
const backgroundConnection = chrome.runtime.connect({
const backgroundConnection = browser.runtime.connect({
name: 'panel',
})

backgroundConnection.postMessage({
name: 'init',
tabId: chrome.devtools.inspectedWindow.tabId,
tabId: browser.devtools.inspectedWindow.tabId,
})

backgroundConnection.onMessage.addListener((message: Message<any>) =>
Expand All @@ -68,7 +69,7 @@ export const Bridge = new (class {
init() {
console.log('Setting up bridge...')

if (!chrome || !chrome.devtools) return
if (!browser || !browser.devtools) return

this.chrome()

Expand Down
14 changes: 8 additions & 6 deletions src/Browser/Background.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defer } from 'lodash'
import browser from 'webextension-polyfill'

type Connection = Map<number, chrome.runtime.Port>
type Connection = Map<number, any>

declare global {
interface Window {
Expand All @@ -15,7 +16,7 @@ const connections: Connection = new Map()
self.connections = connections

const panelListener = () => {
chrome.runtime.onConnect.addListener(port => {
browser.runtime.onConnect.addListener(port => {
console.debug('runtime.onConnect', port)

port.onMessage.addListener(request => {
Expand All @@ -40,7 +41,7 @@ const panelListener = () => {
}

const tabRemovalListener = () => {
chrome.tabs.onRemoved.addListener(tabId => {
browser.tabs.onRemoved.addListener(tabId => {
console.debug('tabs.onRemoved', tabId)

if (connections.has(tabId)) {
Expand All @@ -50,10 +51,10 @@ const tabRemovalListener = () => {
})
}

chrome.action.onClicked.addListener(e => {
browser.browserAction.onClicked.addListener(e => {
console.debug('action.onClicked', e)

chrome.tabs
browser.tabs
.create({
url: 'http://cloud.meteor.com/?utm_source=chrome_extension&utm_medium=extension&utm_campaign=meteor_devtools_evolved',
})
Expand All @@ -72,7 +73,8 @@ const handleConsole = (
}

const contentListener = () => {
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
// @ts-ignore
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
defer(() => {
const tabId = sender?.tab?.id

Expand Down
6 changes: 4 additions & 2 deletions src/Browser/Content.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import browser from 'webextension-polyfill'

const messageHandler = (event: MessageEvent) => {
// Only accept messages from same frame
if (event.source !== window) return

// Only accept messages that we know are ours
if (event.data.source !== 'meteor-devtools-evolved') return

chrome.runtime.sendMessage(event.data)
browser.runtime.sendMessage(event.data)
}

window.addEventListener('message', messageHandler)

const url = chrome.runtime.getURL('/build/inject.js')
const url = browser.runtime.getURL('/build/inject.js')
const script = document.createElement('script')
script.setAttribute('type', 'text/javascript')
script.setAttribute('src', url)
Expand Down
4 changes: 3 additions & 1 deletion src/Browser/DevTools.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
chrome.devtools.panels.create('☄️ Meteor', '', 'devtools-panel.html')
import browser from 'webextension-polyfill'

browser.devtools.panels.create('☄️ Meteor', '', 'devtools-panel.html')
7 changes: 4 additions & 3 deletions src/Pages/Panel/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IMenuItem, ITab, TabBar } from '@/Components/TabBar'
import { Tag } from '@blueprintjs/core'
import { isNumber } from 'lodash'
import { useAnalytics } from '@/Utils/Hooks/useAnalytics'
import browser from 'webextension-polyfill'

export const Navigation: FunctionComponent = observer(() => {
const panelStore = usePanelStore()
Expand Down Expand Up @@ -63,7 +64,7 @@ export const Navigation: FunctionComponent = observer(() => {
key: 'community',
content: '👥 Community',
handler: () => {
chrome.tabs
browser.tabs
.create({
url: 'https://join.slack.com/t/meteor-community/shared_invite/zt-a9lwcfb7-~UwR3Ng6whEqRxcP5rORZw',
})
Expand Down Expand Up @@ -104,7 +105,7 @@ export const Navigation: FunctionComponent = observer(() => {
</>
),
handler: () => {
chrome.tabs
browser.tabs
.create({
url: repositoryData.html_url.concat('/issues'),
})
Expand All @@ -129,7 +130,7 @@ export const Navigation: FunctionComponent = observer(() => {
),
shine: true,
handler: () => {
chrome.tabs
browser.tabs
.create({
url: repositoryData.html_url.concat('/stargazers'),
})
Expand Down
5 changes: 3 additions & 2 deletions src/Pages/Panel/Sponsor/SponsorHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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 '@/Assets/meteor-shower.jpg'

Expand Down Expand Up @@ -76,7 +77,7 @@ export const SponsorHero: FC<Props> = () => {
<button
className='btn btn-primary'
onClick={() =>
chrome.tabs.create({
browser.tabs.create({
url: 'https://social.meteor.com/devtools-evolved',
})
}
Expand All @@ -87,7 +88,7 @@ export const SponsorHero: FC<Props> = () => {
<button
className='btn bg-orange-500 hover:bg-orange-600'
onClick={() =>
chrome.tabs.create({ url: 'mailto:marketing@meteor.com' })
browser.tabs.create({ url: 'mailto:marketing@meteor.com' })
}
>
Email Us the Code
Expand Down
4 changes: 2 additions & 2 deletions webpack/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { CleanWebpackPlugin } = require('clean-webpack-plugin')

const aliases = getTypeScriptAliases()

module.exports = override =>
module.exports = (browser = 'chrome', override) =>
merge(
{
entry: {
Expand All @@ -22,7 +22,7 @@ module.exports = override =>

output: {
chunkFilename: '[name].js',
path: path.join(__dirname, '../chrome/build/'),
path: path.join(__dirname, `../${browser}/build/`),
publicPath: '/build/',
},

Expand Down
2 changes: 1 addition & 1 deletion webpack/chrome.dev.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const base = require('./base')

module.exports = base({
module.exports = base('chrome', {
watch: true,
mode: 'development',
devtool: 'inline-source-map',
Expand Down
2 changes: 1 addition & 1 deletion webpack/chrome.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const base = require('./base')

const TerserPlugin = require('terser-webpack-plugin')

module.exports = base({
module.exports = base('chrome', {
mode: 'production',

optimization: {
Expand Down
10 changes: 10 additions & 0 deletions webpack/firefox.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const base = require('./base')

module.exports = base('firefox', {
watch: true,
mode: 'development',
devtool: 'inline-source-map',
stats: {
modules: false,
},
})
12 changes: 12 additions & 0 deletions webpack/firefox.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const base = require('./base')

const TerserPlugin = require('terser-webpack-plugin')

module.exports = base('firefox', {
mode: 'production',

optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
},
})

0 comments on commit a31114c

Please sign in to comment.