Skip to content

Commit

Permalink
fix: devtools extensions not loading (#20791)
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Oct 30, 2019
1 parent b1fb7c7 commit f279c5e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/renderer/chrome-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ export function injectTo (extensionId: string, context: any) {
let targetExtensionId = extensionId
let connectInfo = { name: '' }
if (args.length === 1) {
targetExtensionId = args[0]
if (typeof args[0] === 'string') {
targetExtensionId = args[0]
} else {
connectInfo = args[0]
}
} else if (args.length === 2) {
[targetExtensionId, connectInfo] = args
}
Expand Down
14 changes: 14 additions & 0 deletions spec/chrome-api-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ describe('chrome api', () => {

afterEach(() => closeWindow(w).then(() => { w = null }))

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 () => {
const actualManifest = (() => {
const data = fs.readFileSync(path.join(fixtures, 'extensions/chrome-api/manifest.json'), 'utf-8')
Expand Down
11 changes: 11 additions & 0 deletions spec/fixtures/extensions/chrome-api/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
})

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 () {
const manifest = chrome.runtime.getManifest()
console.log(JSON.stringify(manifest))
Expand Down

0 comments on commit f279c5e

Please sign in to comment.