Javascript 调用Wait browser.close()时出错:(节点:4960)未处理的PromisejectionWarning:page.goto:导航失败,因为页面已关闭

Javascript 调用Wait browser.close()时出错:(节点:4960)未处理的PromisejectionWarning:page.goto:导航失败,因为页面已关闭,javascript,node.js,asynchronous,promise,playwright,Javascript,Node.js,Asynchronous,Promise,Playwright,我的目标: λ node nav.js First

我的目标:

λ node nav.js                                                                                                                                                                                                                                 
First span is visible. Do something.                                                                                                                                                                                                          
(node:6356) UnhandledPromiseRejectionWarning: page.goto: Navigation failed because page was closed!                                                                                                                                           
=========================== logs ===========================                                                                                                                                                                                  
navigating to "http://localhost:1234/index1.htm", waiting until "load"                                                                                                                                                                         
============================================================                                                                                                                                                                                  
Note: use DEBUG=pw:api environment variable to capture Playwright logs.                                                                                                                                                                       
Error                                                                                                                                                                                                                                         
    at Object.captureStackTrace (C:\repositorios\playwright\node_modules\playwright\lib\utils\stackTrace.js:48:19)                                                                                                                            
    at Connection.sendMessageToServer (C:\repositorios\playwright\node_modules\playwright\lib\client\connection.js:69:48)                                                                                                                     
    at Proxy.<anonymous> (C:\repositorios\playwright\node_modules\playwright\lib\client\channelOwner.js:64:61)                                                                                                                                
    at C:\repositorios\playwright\node_modules\playwright\lib\client\frame.js:102:65                                                                                                                                                          
    at Frame._wrapApiCall (C:\repositorios\playwright\node_modules\playwright\lib\client\channelOwner.js:77:34)                                                                                                                               
    at Frame.goto (C:\repositorios\playwright\node_modules\playwright\lib\client\frame.js:100:21)                                                                                                                                             
    at C:\repositorios\playwright\node_modules\playwright\lib\client\page.js:296:60                                                                                                                                                           
    at Page._attributeToPage (C:\repositorios\playwright\node_modules\playwright\lib\client\page.js:231:20)                                                                                                                                   
    at Page.goto (C:\repositorios\playwright\node_modules\playwright\lib\client\page.js:296:21)                                                                                                                                               
    at C:\repositorios\playwright\nav.js:9:8                                                                                                                                                                                                  
(node:6356) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To termi
nate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)                                                 
(node:6356) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.                                   
在加载第一个页面(一个巨大的html)时导航到第二个页面

当前状态:

λ node nav.js                                                                                                                                                                                                                                 
First span is visible. Do something.                                                                                                                                                                                                          
(node:6356) UnhandledPromiseRejectionWarning: page.goto: Navigation failed because page was closed!                                                                                                                                           
=========================== logs ===========================                                                                                                                                                                                  
navigating to "http://localhost:1234/index1.htm", waiting until "load"                                                                                                                                                                         
============================================================                                                                                                                                                                                  
Note: use DEBUG=pw:api environment variable to capture Playwright logs.                                                                                                                                                                       
Error                                                                                                                                                                                                                                         
    at Object.captureStackTrace (C:\repositorios\playwright\node_modules\playwright\lib\utils\stackTrace.js:48:19)                                                                                                                            
    at Connection.sendMessageToServer (C:\repositorios\playwright\node_modules\playwright\lib\client\connection.js:69:48)                                                                                                                     
    at Proxy.<anonymous> (C:\repositorios\playwright\node_modules\playwright\lib\client\channelOwner.js:64:61)                                                                                                                                
    at C:\repositorios\playwright\node_modules\playwright\lib\client\frame.js:102:65                                                                                                                                                          
    at Frame._wrapApiCall (C:\repositorios\playwright\node_modules\playwright\lib\client\channelOwner.js:77:34)                                                                                                                               
    at Frame.goto (C:\repositorios\playwright\node_modules\playwright\lib\client\frame.js:100:21)                                                                                                                                             
    at C:\repositorios\playwright\node_modules\playwright\lib\client\page.js:296:60                                                                                                                                                           
    at Page._attributeToPage (C:\repositorios\playwright\node_modules\playwright\lib\client\page.js:231:20)                                                                                                                                   
    at Page.goto (C:\repositorios\playwright\node_modules\playwright\lib\client\page.js:296:21)                                                                                                                                               
    at C:\repositorios\playwright\nav.js:9:8                                                                                                                                                                                                  
(node:6356) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To termi
nate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)                                                 
(node:6356) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.                                   
脚本一直工作到结束,然后
等待browser.close()
崩溃

脚本:

λ node nav.js                                                                                                                                                                                                                                 
First span is visible. Do something.                                                                                                                                                                                                          
(node:6356) UnhandledPromiseRejectionWarning: page.goto: Navigation failed because page was closed!                                                                                                                                           
=========================== logs ===========================                                                                                                                                                                                  
navigating to "http://localhost:1234/index1.htm", waiting until "load"                                                                                                                                                                         
============================================================                                                                                                                                                                                  
Note: use DEBUG=pw:api environment variable to capture Playwright logs.                                                                                                                                                                       
Error                                                                                                                                                                                                                                         
    at Object.captureStackTrace (C:\repositorios\playwright\node_modules\playwright\lib\utils\stackTrace.js:48:19)                                                                                                                            
    at Connection.sendMessageToServer (C:\repositorios\playwright\node_modules\playwright\lib\client\connection.js:69:48)                                                                                                                     
    at Proxy.<anonymous> (C:\repositorios\playwright\node_modules\playwright\lib\client\channelOwner.js:64:61)                                                                                                                                
    at C:\repositorios\playwright\node_modules\playwright\lib\client\frame.js:102:65                                                                                                                                                          
    at Frame._wrapApiCall (C:\repositorios\playwright\node_modules\playwright\lib\client\channelOwner.js:77:34)                                                                                                                               
    at Frame.goto (C:\repositorios\playwright\node_modules\playwright\lib\client\frame.js:100:21)                                                                                                                                             
    at C:\repositorios\playwright\node_modules\playwright\lib\client\page.js:296:60                                                                                                                                                           
    at Page._attributeToPage (C:\repositorios\playwright\node_modules\playwright\lib\client\page.js:231:20)                                                                                                                                   
    at Page.goto (C:\repositorios\playwright\node_modules\playwright\lib\client\page.js:296:21)                                                                                                                                               
    at C:\repositorios\playwright\nav.js:9:8                                                                                                                                                                                                  
(node:6356) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To termi
nate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)                                                 
(node:6356) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.                                   
const{chromium}=require(“剧作家”);
(异步()=>{
const browser=wait.launch({headless:false})
const page=wait browser.newPage()
等待page.setViewportSize({宽度:1200,高度:800})
//异步加载
第页转到('http://localhost:1234/index1.htm')
//等待导航到另一页的按钮
等待页面。等待选择器(“#按钮1”);
//按钮已存在。单击该按钮可导航到index2.htm
等待页面。单击(“#按钮1”)
//等待index2.htm中存在的#first_span元素执行某些操作
等待页面。waitForSelector(“#first_span”)
//做某事
console.log('第一个跨度可见。请执行操作')
//完成浏览器(这会导致错误)
等待浏览器关闭()
})()
错误:

λ node nav.js                                                                                                                                                                                                                                 
First span is visible. Do something.                                                                                                                                                                                                          
(node:6356) UnhandledPromiseRejectionWarning: page.goto: Navigation failed because page was closed!                                                                                                                                           
=========================== logs ===========================                                                                                                                                                                                  
navigating to "http://localhost:1234/index1.htm", waiting until "load"                                                                                                                                                                         
============================================================                                                                                                                                                                                  
Note: use DEBUG=pw:api environment variable to capture Playwright logs.                                                                                                                                                                       
Error                                                                                                                                                                                                                                         
    at Object.captureStackTrace (C:\repositorios\playwright\node_modules\playwright\lib\utils\stackTrace.js:48:19)                                                                                                                            
    at Connection.sendMessageToServer (C:\repositorios\playwright\node_modules\playwright\lib\client\connection.js:69:48)                                                                                                                     
    at Proxy.<anonymous> (C:\repositorios\playwright\node_modules\playwright\lib\client\channelOwner.js:64:61)                                                                                                                                
    at C:\repositorios\playwright\node_modules\playwright\lib\client\frame.js:102:65                                                                                                                                                          
    at Frame._wrapApiCall (C:\repositorios\playwright\node_modules\playwright\lib\client\channelOwner.js:77:34)                                                                                                                               
    at Frame.goto (C:\repositorios\playwright\node_modules\playwright\lib\client\frame.js:100:21)                                                                                                                                             
    at C:\repositorios\playwright\node_modules\playwright\lib\client\page.js:296:60                                                                                                                                                           
    at Page._attributeToPage (C:\repositorios\playwright\node_modules\playwright\lib\client\page.js:231:20)                                                                                                                                   
    at Page.goto (C:\repositorios\playwright\node_modules\playwright\lib\client\page.js:296:21)                                                                                                                                               
    at C:\repositorios\playwright\nav.js:9:8                                                                                                                                                                                                  
(node:6356) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To termi
nate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)                                                 
(node:6356) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.                                   
λ节点nav.js
第一个跨度是可见的。做点什么。
(节点:6356)未处理的PromisejectionWarning:page.goto:导航失败,因为页面已关闭!
===========================================================================================================================
导航到“http://localhost:1234/index1.htm,等待“加载”
============================================================                                                                                                                                                                                  
注意:使用DEBUG=pw:api环境变量捕获剧作家日志。
错误
在Object.captureStackTrace(C:\repositorios\playright\node\u modules\playright\lib\utils\stackTrace.js:48:19)
在Connection.sendMessageToServer(C:\repositorios\playright\node\u modules\playright\lib\client\Connection.js:69:48)
代理。(C:\repositorios\playright\node\u modules\playright\lib\client\channelOwner.js:64:61)
在C:\repositorios\playright\node\u modules\playright\lib\client\frame.js:102:65
在帧处调用(C:\repositorios\playright\node\u modules\playright\lib\client\channelOwner.js:77:34)
在Frame.goto(C:\repositorios\playright\node\u modules\playright\lib\client\Frame.js:100:21)
在C:\repositorios\playright\node\u modules\playright\lib\client\page.js:296:60
在第页。\ u属性页(C:\repositorios\playright\node\u modules\playright\lib\client\Page.js:231:20)
在Page.goto(C:\repositorios\playright\node\u modules\playright\lib\client\Page.js:296:21)
在C:\repositorios\playstright\nav.js:9:8
(节点:6356)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。托特米
在未处理的承诺拒绝上指定节点进程,请使用CLI标志“---unhandled rejections=strict”(请参阅https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (拒绝id:1)
(n)