Skip to content

Commit 7e9f3cb

Browse files
committed
fix: api regressions from mv3 changes
1 parent 67cdd22 commit 7e9f3cb

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

packages/electron-chrome-extensions/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"mocha": "^8.2.1",
4141
"ts-node": "^10.9.1",
4242
"typescript": "^4.9.4",
43-
"uuid": "^8.3.1",
4443
"walkdir": "^0.4.1",
4544
"webpack": "^5.73.0",
4645
"webpack-cli": "^4.10.0"

packages/electron-chrome-extensions/spec/chrome-contextMenus-spec.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai'
22
import { ipcMain } from 'electron'
3-
import { emittedOnce } from './events-helpers'
3+
import { once } from 'node:events'
44

55
import { useExtensionBrowser, useServer } from './hooks'
66
import { uuid } from './spec-helpers'
@@ -13,22 +13,18 @@ describe('chrome.contextMenus', () => {
1313
})
1414

1515
const getContextMenuItems = async () => {
16-
const promise = new Promise<Electron.MenuItem[]>((resolve) => {
17-
browser.webContents.once('context-menu', (_, params) => {
18-
const items = browser.extensions.getContextMenuItems(browser.webContents, params)
19-
resolve(items)
20-
})
21-
})
22-
2316
// TODO: why is this needed since upgrading to Electron 22?
2417
await new Promise((resolve) => setTimeout(resolve, 1000))
2518

19+
const contextMenuPromise = once(browser.webContents, 'context-menu')
20+
2621
// Simulate right-click to create context-menu event.
2722
const opts = { x: 0, y: 0, button: 'right' as any }
2823
browser.webContents.sendInputEvent({ ...opts, type: 'mouseDown' })
2924
browser.webContents.sendInputEvent({ ...opts, type: 'mouseUp' })
3025

31-
return await promise
26+
const [, params] = await contextMenuPromise
27+
return browser.extensions.getContextMenuItems(browser.webContents, params)
3228
}
3329

3430
describe('create()', () => {
@@ -74,7 +70,7 @@ describe('chrome.contextMenus', () => {
7470
onclick: { __IPC_FN__: ipcName },
7571
})
7672
const items = await getContextMenuItems()
77-
const p = emittedOnce(ipcMain, ipcName)
73+
const p = once(ipcMain, ipcName)
7874
items[0].click()
7975
await p
8076
})

packages/electron-chrome-extensions/spec/spec-helpers.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2020
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22-
import * as childProcess from 'child_process'
23-
import * as path from 'path'
24-
import * as http from 'http'
22+
import * as childProcess from 'node:child_process'
23+
import * as nodeCrypto from 'node:crypto'
24+
import * as path from 'node:path'
25+
import * as http from 'node:http'
2526
import * as v8 from 'v8'
2627
import { SuiteFunction, TestFunction } from 'mocha'
2728

@@ -132,4 +133,4 @@ export async function getFiles(directoryPath: string, { filter = null }: any = {
132133
return files
133134
}
134135

135-
export const uuid = () => require('uuid').v4()
136+
export const uuid = () => nodeCrypto.randomUUID()

packages/electron-chrome-extensions/src/browser/api/browser-action.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ const getBrowserActionDefaults = (extension: Electron.Extension): ExtensionActio
4242
manifest.manifest_version === 3
4343
? manifest.action
4444
: manifest.manifest_version === 2
45-
? manifest.browser_action
46-
: undefined
45+
? manifest.browser_action
46+
: undefined
4747
if (typeof browserAction === 'object') {
4848
const manifestAction: chrome.runtime.ManifestAction = browserAction
4949
const action: ExtensionAction = {}
@@ -106,7 +106,7 @@ export class BrowserActionAPI {
106106
const { tabId } = details
107107
let value = details[propName]
108108

109-
if (typeof value === 'undefined') {
109+
if (typeof value === 'undefined' || value === null) {
110110
const defaults = getBrowserActionDefaults(extension)
111111
value = defaults ? defaults[propName] : value
112112
}

packages/electron-chrome-extensions/src/browser/api/context-menus.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ const matchesConditions = (
5454

5555
const { contextTypes, targetUrl, documentUrl } = conditions
5656

57-
const contexts = (Array.isArray(props.contexts) ? props.contexts : [props.contexts]) || DEFAULT_CONTEXTS
57+
const contexts = props.contexts
58+
? Array.isArray(props.contexts)
59+
? props.contexts
60+
: [props.contexts]
61+
: DEFAULT_CONTEXTS
5862
const inContext = contexts.some((context) => contextTypes.has(context as ContextMenuType))
5963
if (!inContext) return false
6064

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7207,7 +7207,7 @@ [email protected]:
72077207
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
72087208
integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==
72097209

7210-
uuid@^8.3.1, uuid@^8.3.2:
7210+
uuid@^8.3.2:
72117211
version "8.3.2"
72127212
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
72137213
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

0 commit comments

Comments
 (0)