1- const exceptions = require ( "./exceptions" ) ;
1+ const { Browser } = require ( 'puppeteer' ) ;
22const { proxyRequest } = require ( 'puppeteer-proxy' ) ;
3- const timeoutContext = require ( './timeout_context' ) ;
4- const limitContext = require ( './limit_context' ) ;
53const PuppeteerHar = require ( 'puppeteer-har' ) ;
64
5+ const exceptions = require ( "./exceptions" ) ;
6+ const limitContext = require ( './limit_context' ) ;
7+ const timeoutContext = require ( './timeout_context' ) ;
8+
79const PROXY_URL_KEY = 'puppeteer-service-proxy-url'
810
911async function findContextInBrowser ( browser , contextId ) {
@@ -24,6 +26,12 @@ async function findPageInContext(context, pageId) {
2426 throw new exceptions . PageNotFoundError ( ) ;
2527}
2628
29+ /**
30+ * Close contexts in browser.
31+ *
32+ * @param {Browser } browser Browser with contexts to close.
33+ * @param {[string] } contextIds Context ids to close.
34+ **/
2735exports . closeContexts = async function closeContexts ( browser , contextIds ) {
2836 // TODO shared locks on contexts and exclusive on pages?
2937 const closePromises = [ ] ;
@@ -71,6 +79,7 @@ async function wait(page, waitFor) {
7179
7280/***
7381 * This function returns `pageId` and `contextId` of corresponding page.
82+ *
7483 * @param page
7584 * @returns Promise
7685 */
@@ -94,10 +103,11 @@ exports.getContents = async function getContents(page, waitFor) {
94103
95104async function newPage ( context , request ) {
96105 const page = await context . newPage ( ) ;
106+
97107 if ( request . body . harRecording ) {
98- const harWriter = new PuppeteerHar ( page )
99- harWriter . start ( )
100- page . harWriter = harWriter
108+ const harWriter = new PuppeteerHar ( page ) ;
109+ await harWriter . start ( ) ;
110+ page . harWriter = harWriter ;
101111 }
102112
103113 await page . setRequestInterception ( true ) ;
@@ -125,7 +135,7 @@ async function newContext(browser, options = {}) {
125135 const context = await browser . createIncognitoBrowserContext ( options ) ;
126136 limitContext . incContextCounter ( ) ;
127137 timeoutContext . setContextTimeout ( context ) ;
128- return context
138+ return context ;
129139 } catch ( err ) {
130140 limitContext . decContextCounter ( ) ;
131141 throw err ;
@@ -141,6 +151,7 @@ function getProxy(request) {
141151/***
142152 * This function returns a page from browser context or create new page or even context if pageId or contextId are
143153 * none. If no context or now page found throw an error.
154+ *
144155 * @param browser
145156 * @param request
146157 * @returns {Promise<Page> }
0 commit comments