feat(extensions): add chrome.tabs.connect API (#22457)
* feat(extensions): add chrome.tabs.connect API * test(extensions): verify that chrome.tabs.connect port communication works
This commit is contained in:
parent
d6701ff435
commit
0201b3e571
4 changed files with 62 additions and 0 deletions
|
@ -186,6 +186,22 @@ ifdescribe(process.electronBinding('features').isExtensionsEnabled())('chrome ex
|
|||
expect(response).to.equal(3)
|
||||
})
|
||||
|
||||
it('connect', async () => {
|
||||
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`)
|
||||
await customSession.loadExtension(path.join(fixtures, 'extensions', 'chrome-api'))
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, nodeIntegration: true } })
|
||||
await w.loadURL(url)
|
||||
|
||||
const portName = require('uuid').v4()
|
||||
const message = { method: 'connectTab', args: [portName] }
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`)
|
||||
|
||||
const [,, responseString] = await emittedOnce(w.webContents, 'console-message')
|
||||
const response = responseString.split(',')
|
||||
expect(response[0]).to.equal(portName)
|
||||
expect(response[1]).to.equal('howdy')
|
||||
})
|
||||
|
||||
it('sendMessage receives the response', async function () {
|
||||
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`)
|
||||
await customSession.loadExtension(path.join(fixtures, 'extensions', 'chrome-api'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue