Skip to content

Commit

Permalink
fix: api regressions from mv3 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmaddock committed Dec 13, 2024
1 parent 5ba6eb0 commit 0e83afc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
1 change: 0 additions & 1 deletion packages/electron-chrome-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"mocha": "^8.2.1",
"ts-node": "^10.9.1",
"typescript": "^4.9.4",
"uuid": "^8.3.1",
"walkdir": "^0.4.1",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai'
import { ipcMain } from 'electron'
import { emittedOnce } from './events-helpers'
import { once } from 'node:events'

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

const getContextMenuItems = async () => {
const promise = new Promise<Electron.MenuItem[]>((resolve) => {
browser.webContents.once('context-menu', (_, params) => {
const items = browser.extensions.getContextMenuItems(browser.webContents, params)
resolve(items)
})
})

// TODO: why is this needed since upgrading to Electron 22?
await new Promise((resolve) => setTimeout(resolve, 1000))

const contextMenuPromise = once(browser.webContents, 'context-menu')

// Simulate right-click to create context-menu event.
const opts = { x: 0, y: 0, button: 'right' as any }
browser.webContents.sendInputEvent({ ...opts, type: 'mouseDown' })
browser.webContents.sendInputEvent({ ...opts, type: 'mouseUp' })

return await promise
const [, params] = await contextMenuPromise
return browser.extensions.getContextMenuItems(browser.webContents, params)
}

describe('create()', () => {
Expand Down Expand Up @@ -74,7 +70,7 @@ describe('chrome.contextMenus', () => {
onclick: { __IPC_FN__: ipcName },
})
const items = await getContextMenuItems()
const p = emittedOnce(ipcMain, ipcName)
const p = once(ipcMain, ipcName)
items[0].click()
await p
})
Expand Down
9 changes: 5 additions & 4 deletions packages/electron-chrome-extensions/spec/spec-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import * as childProcess from 'child_process'
import * as path from 'path'
import * as http from 'http'
import * as childProcess from 'node:child_process'
import * as nodeCrypto from 'node:crypto'
import * as path from 'node:path'
import * as http from 'node:http'
import * as v8 from 'v8'
import { SuiteFunction, TestFunction } from 'mocha'

Expand Down Expand Up @@ -132,4 +133,4 @@ export async function getFiles(directoryPath: string, { filter = null }: any = {
return files
}

export const uuid = () => require('uuid').v4()
export const uuid = () => nodeCrypto.randomUUID()
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const getBrowserActionDefaults = (extension: Electron.Extension): ExtensionActio
manifest.manifest_version === 3
? manifest.action
: manifest.manifest_version === 2
? manifest.browser_action
: undefined
? manifest.browser_action
: undefined
if (typeof browserAction === 'object') {
const manifestAction: chrome.runtime.ManifestAction = browserAction
const action: ExtensionAction = {}
Expand Down Expand Up @@ -106,7 +106,7 @@ export class BrowserActionAPI {
const { tabId } = details
let value = details[propName]

if (typeof value === 'undefined') {
if (typeof value === 'undefined' || value === null) {
const defaults = getBrowserActionDefaults(extension)
value = defaults ? defaults[propName] : value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ const matchesConditions = (

const { contextTypes, targetUrl, documentUrl } = conditions

const contexts = (Array.isArray(props.contexts) ? props.contexts : [props.contexts]) || DEFAULT_CONTEXTS
const contexts = props.contexts
? Array.isArray(props.contexts)
? props.contexts
: [props.contexts]
: DEFAULT_CONTEXTS
const inContext = contexts.some((context) => contextTypes.has(context as ContextMenuType))
if (!inContext) return false

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7207,7 +7207,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==

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

0 comments on commit 0e83afc

Please sign in to comment.