fix: devtools extensions not loading (#20791)
This commit is contained in:
parent
0ab9cc30d2
commit
3d56e13b38
3 changed files with 30 additions and 1 deletions
|
@ -120,7 +120,11 @@ export function injectTo (extensionId: string, context: any) {
|
||||||
let targetExtensionId = extensionId
|
let targetExtensionId = extensionId
|
||||||
let connectInfo = { name: '' }
|
let connectInfo = { name: '' }
|
||||||
if (args.length === 1) {
|
if (args.length === 1) {
|
||||||
targetExtensionId = args[0]
|
if (typeof args[0] === 'string') {
|
||||||
|
targetExtensionId = args[0]
|
||||||
|
} else {
|
||||||
|
connectInfo = args[0]
|
||||||
|
}
|
||||||
} else if (args.length === 2) {
|
} else if (args.length === 2) {
|
||||||
[targetExtensionId, connectInfo] = args
|
[targetExtensionId, connectInfo] = args
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,20 @@ ifdescribe(!process.electronBinding('features').isExtensionsEnabled())('chrome e
|
||||||
|
|
||||||
afterEach(() => closeWindow(w).then(() => { w = null as unknown as BrowserWindow }))
|
afterEach(() => closeWindow(w).then(() => { w = null as unknown as BrowserWindow }))
|
||||||
|
|
||||||
|
it('chrome.runtime.connect parses arguments properly', async function () {
|
||||||
|
await w.loadURL('about:blank')
|
||||||
|
|
||||||
|
const promise = emittedOnce(w.webContents, 'console-message')
|
||||||
|
|
||||||
|
const message = { method: 'connect' }
|
||||||
|
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`)
|
||||||
|
|
||||||
|
const [,, responseString] = await promise
|
||||||
|
const response = JSON.parse(responseString)
|
||||||
|
|
||||||
|
expect(response).to.be.true()
|
||||||
|
})
|
||||||
|
|
||||||
it('runtime.getManifest returns extension manifest', async () => {
|
it('runtime.getManifest returns extension manifest', async () => {
|
||||||
const actualManifest = (() => {
|
const actualManifest = (() => {
|
||||||
const data = fs.readFileSync(path.join(fixtures, 'extensions/chrome-api/manifest.json'), 'utf-8')
|
const data = fs.readFileSync(path.join(fixtures, 'extensions/chrome-api/manifest.json'), 'utf-8')
|
||||||
|
|
11
spec/fixtures/extensions/chrome-api/main.js
vendored
11
spec/fixtures/extensions/chrome-api/main.js
vendored
|
@ -5,6 +5,17 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const testMap = {
|
const testMap = {
|
||||||
|
connect () {
|
||||||
|
let success = false
|
||||||
|
try {
|
||||||
|
chrome.runtime.connect(chrome.runtime.id)
|
||||||
|
chrome.runtime.connect(chrome.runtime.id, { name: 'content-script' })
|
||||||
|
chrome.runtime.connect({ name: 'content-script' })
|
||||||
|
success = true
|
||||||
|
} finally {
|
||||||
|
console.log(JSON.stringify(success))
|
||||||
|
}
|
||||||
|
},
|
||||||
getManifest () {
|
getManifest () {
|
||||||
const manifest = chrome.runtime.getManifest()
|
const manifest = chrome.runtime.getManifest()
|
||||||
console.log(JSON.stringify(manifest))
|
console.log(JSON.stringify(manifest))
|
||||||
|
|
Loading…
Add table
Reference in a new issue