Merge pull request #224 from getmaxun/goto-fix
fix: emit socket `urlChanged` on frame navigation
This commit is contained in:
@@ -165,6 +165,13 @@ export class RemoteBrowser {
|
|||||||
contextOptions.userAgent = browserUserAgent;
|
contextOptions.userAgent = browserUserAgent;
|
||||||
this.context = await this.browser.newContext(contextOptions);
|
this.context = await this.browser.newContext(contextOptions);
|
||||||
this.currentPage = await this.context.newPage();
|
this.currentPage = await this.context.newPage();
|
||||||
|
|
||||||
|
this.currentPage.on('framenavigated', (frame) => {
|
||||||
|
if (frame === this.currentPage?.mainFrame()) {
|
||||||
|
this.socket.emit('urlChanged', this.currentPage.url());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// await this.currentPage.setExtraHTTPHeaders({
|
// await this.currentPage.setExtraHTTPHeaders({
|
||||||
// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
|
// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
|
||||||
// });
|
// });
|
||||||
@@ -362,6 +369,13 @@ export class RemoteBrowser {
|
|||||||
if (page) {
|
if (page) {
|
||||||
await this.stopScreencast();
|
await this.stopScreencast();
|
||||||
this.currentPage = page;
|
this.currentPage = page;
|
||||||
|
|
||||||
|
this.currentPage.on('framenavigated', (frame) => {
|
||||||
|
if (frame === this.currentPage?.mainFrame()) {
|
||||||
|
this.socket.emit('urlChanged', this.currentPage.url());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//await this.currentPage.setViewportSize({ height: 400, width: 900 })
|
//await this.currentPage.setViewportSize({ height: 400, width: 900 })
|
||||||
this.client = await this.currentPage.context().newCDPSession(this.currentPage);
|
this.client = await this.currentPage.context().newCDPSession(this.currentPage);
|
||||||
this.socket.emit('urlChanged', this.currentPage.url());
|
this.socket.emit('urlChanged', this.currentPage.url());
|
||||||
@@ -388,9 +402,14 @@ export class RemoteBrowser {
|
|||||||
await this.currentPage?.close();
|
await this.currentPage?.close();
|
||||||
this.currentPage = newPage;
|
this.currentPage = newPage;
|
||||||
if (this.currentPage) {
|
if (this.currentPage) {
|
||||||
this.currentPage.on('load', (page) => {
|
this.currentPage.on('framenavigated', (frame) => {
|
||||||
this.socket.emit('urlChanged', page.url());
|
if (frame === this.currentPage?.mainFrame()) {
|
||||||
})
|
this.socket.emit('urlChanged', this.currentPage.url());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// this.currentPage.on('load', (page) => {
|
||||||
|
// this.socket.emit('urlChanged', page.url());
|
||||||
|
// })
|
||||||
this.client = await this.currentPage.context().newCDPSession(this.currentPage);
|
this.client = await this.currentPage.context().newCDPSession(this.currentPage);
|
||||||
await this.subscribeToScreencast();
|
await this.subscribeToScreencast();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user