feat: expose frame & move properties to console-message event object (#43617)
* feat: expose frame on console-message event refactor: use property names similar to ServiceWorker's console-message event refactor: don't use deprecated params in tests doc: console-message breaking change chore: add deprecation warning docs: restore deprecated argument descriptions * move console-message deprecations to v34 --------- Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
parent
35aeab6ecd
commit
87bd665e41
13 changed files with 140 additions and 65 deletions
|
@ -111,7 +111,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'query' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
|
||||
expect(response).to.have.lengthOf(1);
|
||||
|
@ -434,7 +434,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'executeScript', args: ['1 + 2'] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [, , responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
|
||||
expect(response).to.equal(3);
|
||||
|
@ -448,7 +448,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'connectTab', args: [portName] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = responseString.split(',');
|
||||
expect(response[0]).to.equal(portName);
|
||||
expect(response[1]).to.equal('howdy');
|
||||
|
@ -461,7 +461,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'sendMessage', args: ['Hello World!'] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
|
||||
expect(response.message).to.equal('Hello World!');
|
||||
|
@ -480,7 +480,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'update', args: [w2.webContents.id, { url }] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
|
||||
await w2Navigated;
|
||||
|
@ -801,7 +801,7 @@ describe('chrome extensions', () => {
|
|||
|
||||
w.webContents.executeJavaScript('window.postMessage(\'fetch-confirmation\', \'*\')');
|
||||
|
||||
const [, , responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const { message } = JSON.parse(responseString);
|
||||
|
||||
expect(message).to.equal('Hello from background.js');
|
||||
|
@ -834,7 +834,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'getAcceptLanguages' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
|
||||
expect(response).to.be.an('array').that.is.not.empty('languages array is empty');
|
||||
|
@ -846,7 +846,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'getUILanguage' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
|
||||
expect(response).to.be.a('string');
|
||||
|
@ -858,7 +858,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'getMessage' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [, , responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
|
||||
expect(response).to.equal('Hola mundo!!');
|
||||
|
@ -877,7 +877,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'detectLanguage', args: [greetings] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [, , responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
|
||||
expect(response).to.be.an('array');
|
||||
|
@ -925,7 +925,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'isEnabled' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [, , responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).to.equal(false);
|
||||
|
@ -937,7 +937,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'setIcon' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [, , responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).to.equal(null);
|
||||
|
@ -949,7 +949,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'getBadgeText' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [, , responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).to.equal('');
|
||||
|
@ -982,7 +982,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'getZoom' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).to.equal(1);
|
||||
|
@ -994,7 +994,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'setZoom', args: [2] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).to.deep.equal(2);
|
||||
|
@ -1006,7 +1006,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'getZoomSettings' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).to.deep.equal({
|
||||
|
@ -1022,7 +1022,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'setZoomSettings', args: [{ mode: 'disabled' }] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).to.deep.equal({
|
||||
|
@ -1039,7 +1039,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'get' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).to.have.property('url').that.is.a('string');
|
||||
|
@ -1065,7 +1065,7 @@ describe('chrome extensions', () => {
|
|||
await w.loadURL(url);
|
||||
|
||||
w.webContents.executeJavaScript('window.postMessage(\'{}\', \'*\')');
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).not.to.have.property('url');
|
||||
expect(response).not.to.have.property('title');
|
||||
|
@ -1092,7 +1092,7 @@ describe('chrome extensions', () => {
|
|||
const consoleMessage = once(w.webContents, 'console-message');
|
||||
const finish = once(w.webContents, 'did-finish-load');
|
||||
|
||||
await Promise.all([consoleMessage, finish]).then(([[,, responseString]]) => {
|
||||
await Promise.all([consoleMessage, finish]).then(([[{ message: responseString }]]) => {
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response.status).to.equal('reloaded');
|
||||
});
|
||||
|
@ -1105,7 +1105,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'update', args: [{ muted: true }] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
|
||||
expect(response).to.have.property('mutedInfo').that.is.a('object');
|
||||
|
@ -1122,7 +1122,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'update', args: [{ url: 'chrome://crash' }] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const { error } = JSON.parse(responseString);
|
||||
expect(error).to.eq('I\'m sorry. I\'m afraid I can\'t do that.');
|
||||
});
|
||||
|
@ -1133,7 +1133,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'update', args: [{ url: 'chrome://crash' }] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const { error } = JSON.parse(responseString);
|
||||
expect(error).to.eq('I\'m sorry. I\'m afraid I can\'t do that.');
|
||||
});
|
||||
|
@ -1144,7 +1144,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'update', args: [{ url: 'devtools://blah' }] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [, , responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const { error } = JSON.parse(responseString);
|
||||
expect(error).to.eq('Cannot navigate to a devtools:// page without either the devtools or debugger permission.');
|
||||
});
|
||||
|
@ -1155,7 +1155,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'update', args: [{ url: 'chrome-untrusted://blah' }] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [, , responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const { error } = JSON.parse(responseString);
|
||||
expect(error).to.eq('Cannot navigate to a chrome-untrusted:// page.');
|
||||
});
|
||||
|
@ -1166,7 +1166,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'update', args: [{ url: 'file://blah' }] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [, , responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const { error } = JSON.parse(responseString);
|
||||
expect(error).to.eq('Cannot navigate to a file URL without local file access.');
|
||||
});
|
||||
|
@ -1183,7 +1183,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'query', args: [{ muted: true }] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [, , responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).to.have.lengthOf(1);
|
||||
|
||||
|
@ -1220,7 +1220,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'query', args: [{ muted: true }] };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [, , responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).to.have.lengthOf(2);
|
||||
for (const tab of response) {
|
||||
|
@ -1270,7 +1270,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'registerContentScripts' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).to.be.an('array').with.lengthOf(1);
|
||||
expect(response[0]).to.deep.equal({
|
||||
|
@ -1290,7 +1290,7 @@ describe('chrome extensions', () => {
|
|||
|
||||
const message = { method: 'globalParams' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response).to.deep.equal({ changed: true });
|
||||
});
|
||||
|
@ -1304,7 +1304,7 @@ describe('chrome extensions', () => {
|
|||
const message = { method: 'insertCSS' };
|
||||
w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
|
||||
|
||||
const [,, responseString] = await once(w.webContents, 'console-message');
|
||||
const [{ message: responseString }] = await once(w.webContents, 'console-message');
|
||||
const response = JSON.parse(responseString);
|
||||
expect(response.success).to.be.true();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue