feat: add <webview> 'did-redirect-navigation' event (#30457)
This commit is contained in:
parent
34f1bc0e82
commit
aad1c0d493
3 changed files with 53 additions and 0 deletions
|
@ -847,6 +847,19 @@ Returns:
|
||||||
Emitted when any frame (including main) starts navigating. `isInPlace` will be
|
Emitted when any frame (including main) starts navigating. `isInPlace` will be
|
||||||
`true` for in-page navigations.
|
`true` for in-page navigations.
|
||||||
|
|
||||||
|
### Event: 'did-redirect-navigation'
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
* `url` String
|
||||||
|
* `isInPlace` Boolean
|
||||||
|
* `isMainFrame` Boolean
|
||||||
|
* `frameProcessId` Integer
|
||||||
|
* `frameRoutingId` Integer
|
||||||
|
|
||||||
|
Emitted after a server side redirect occurs during navigation. For example a 302
|
||||||
|
redirect.
|
||||||
|
|
||||||
### Event: 'did-navigate'
|
### Event: 'did-navigate'
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
|
@ -14,6 +14,7 @@ export const webViewEvents: Record<string, readonly string[]> = {
|
||||||
'devtools-focused': [],
|
'devtools-focused': [],
|
||||||
'will-navigate': ['url'],
|
'will-navigate': ['url'],
|
||||||
'did-start-navigation': ['url', 'isInPlace', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
'did-start-navigation': ['url', 'isInPlace', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
||||||
|
'did-redirect-navigation': ['url', 'isInPlace', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
||||||
'did-navigate': ['url', 'httpResponseCode', 'httpStatusText'],
|
'did-navigate': ['url', 'httpResponseCode', 'httpStatusText'],
|
||||||
'did-frame-navigate': ['url', 'httpResponseCode', 'httpStatusText', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
'did-frame-navigate': ['url', 'httpResponseCode', 'httpStatusText', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
||||||
'did-navigate-in-page': ['url', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
'did-navigate-in-page': ['url', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
||||||
|
|
|
@ -564,6 +564,45 @@ describe('<webview> tag', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('did-redirect-navigation event', () => {
|
||||||
|
let server = null;
|
||||||
|
let uri = null;
|
||||||
|
|
||||||
|
before((done) => {
|
||||||
|
server = http.createServer((req, res) => {
|
||||||
|
if (req.url === '/302') {
|
||||||
|
res.setHeader('Location', '/200');
|
||||||
|
res.statusCode = 302;
|
||||||
|
res.end();
|
||||||
|
} else {
|
||||||
|
res.end();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
server.listen(0, '127.0.0.1', () => {
|
||||||
|
uri = `http://127.0.0.1:${(server.address()).port}`;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
server.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is emitted on redirects', async () => {
|
||||||
|
loadWebView(webview, {
|
||||||
|
src: `${uri}/302`
|
||||||
|
});
|
||||||
|
|
||||||
|
const event = await waitForEvent(webview, 'did-redirect-navigation');
|
||||||
|
|
||||||
|
expect(event.url).to.equal(`${uri}/200`);
|
||||||
|
expect(event.isInPlace).to.be.false();
|
||||||
|
expect(event.isMainFrame).to.be.true();
|
||||||
|
expect(event.frameProcessId).to.be.a('number');
|
||||||
|
expect(event.frameRoutingId).to.be.a('number');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('will-navigate event', () => {
|
describe('will-navigate event', () => {
|
||||||
it('emits when a url that leads to oustide of the page is clicked', async () => {
|
it('emits when a url that leads to oustide of the page is clicked', async () => {
|
||||||
loadWebView(webview, {
|
loadWebView(webview, {
|
||||||
|
|
Loading…
Reference in a new issue