Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions add-on/manifest.chromium.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"minimum_chrome_version": "72",
"permissions": [
"clipboardWrite",
"contextMenus",
"idle",
"tabs",
"notifications",
"storage",
"tabs",
"unlimitedStorage",
"contextMenus",
"clipboardWrite",
"webNavigation",
"webRequest"
],
"host_permissions": ["<all_urls>"],
"incognito": "not_allowed"
}
3 changes: 1 addition & 2 deletions add-on/manifest.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"128": "icons/png/ipfs-logo-on_128.png"
},
"background": {
"service_worker": "dist/bundles/backgroundPage.bundle.js",
"type": "module"
"service_worker": "dist/bundles/backgroundPage.bundle.js"
Comment on lines 14 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no module type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add this back later, this seems to break things for now.

},
"action": {
"default_icon": {
Expand Down
19 changes: 5 additions & 14 deletions add-on/src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@
/* eslint-env browser, webextensions */

import browser from 'webextension-polyfill'
import createIpfsCompanion from '../lib/ipfs-companion.js'
import { onInstalled } from '../lib/on-installed.js'
import { getUninstallURL } from '../lib/on-uninstalled.js'
import { optionDefaults } from '../lib/options.js'
import createIpfsCompanion from '../lib/ipfs-companion.js'

// register lifecycle hooks early, otherwise we miss first install event
browser.runtime.onInstalled.addListener(onInstalled)
browser.runtime.setUninstallURL(getUninstallURL(browser))

// init add-on after all libs are loaded
document.addEventListener('DOMContentLoaded', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we still listening for domcontentloaded somewhere else or is this no longer needed at all? I know the background is ran in service worker now, so maybe we don't need it at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will still be needed in popup and other pages with windowed context.

// setting debug namespaces require page reload to get applied
const debugNs = (await browser.storage.local.get({ logNamespaces: optionDefaults.logNamespaces })).logNamespaces
if (debugNs !== localStorage.debug) {
localStorage.debug = debugNs
window.location.reload()
}
// init inlined to read updated localStorage.debug
// @ts-expect-error - TS does not know about window.ipfsCompanion
window.ipfsCompanion = await createIpfsCompanion()
})
const init = async () => {
await createIpfsCompanion()
}
init();
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"url": "https://github.com/ipfs-shipyard/ipfs-companion.git"
},
"type": "module",
"sideEffects": [
"*.css"
],
"scripts": {
"start": "run-s clean build test firefox",
"clean": "run-p clean:*",
Expand Down
32 changes: 32 additions & 0 deletions patches/debug+4.3.4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/node_modules/debug/src/browser.js b/node_modules/debug/src/browser.js
index cd0fc35..794db58 100644
--- a/node_modules/debug/src/browser.js
+++ b/node_modules/debug/src/browser.js
Comment on lines +1 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a PR out for this patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope this is the PR.

@@ -116,7 +116,7 @@ function useColors() {
// NB: In an Electron preload script, document will be defined but not fully
// initialized. Since we know we're in Chrome, we'll just detect this case
// explicitly
- if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
+ if (typeof globalThis !== 'undefined' && globalThis.process && (globalThis.process.type === 'renderer' || globalThis.process.__nwjs)) {
return true;
}

@@ -129,7 +129,7 @@ function useColors() {
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
// Is firebug? http://stackoverflow.com/a/398120/376773
- (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
+ (typeof globalThis !== 'undefined' && globalThis.console && (globalThis.console.firebug || (globalThis.console.exception && globalThis.console.table))) ||
// Is firefox >= v31?
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
@@ -245,6 +245,9 @@ function localstorage() {
try {
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
// The Browser also has localStorage in the global context.
+ if (chrome?.storage?.local) {
+ return chrome.storage.local;
+ }
return localStorage;
} catch (error) {
// Swallow
6 changes: 5 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const commonConfig = {
Buffer: ['buffer/', 'Buffer'] // ensure version from package.json is used
}),
new webpack.DefinePlugin({
global: 'window', // https://github.com/webpack/webpack/issues/5627#issuecomment-394309966
global: 'globalThis', // https://github.com/webpack/webpack/issues/5627#issuecomment-394309966
'process.emitWarning': (message, type) => {}, // console.warn(`${type}${type ? ': ' : ''}${message}`),
'process.env': {
// NODE_ENV: '"production"',
Expand Down Expand Up @@ -125,9 +125,13 @@ if (devBuild) {
*/
const bgConfig = merge(commonConfig, {
name: 'background',
target: 'webworker',
entry: {
backgroundPage: './add-on/src/background/background.js'
},
output: {
globalObject: 'globalThis'
},
optimization: {
splitChunks: {
chunks: 'all',
Expand Down