11import url from "url" ;
22import _ from "lodash" ;
3- import { parse as parseCookiesString , Cookie } from "set-cookie-parser" ;
43import { attach , type AttachOptions , type ElementArray } from "@testplane/webdriverio" ;
54import { sessionEnvironmentDetector } from "@testplane/wdio-utils" ;
65import { Browser , BrowserOpts } from "./browser" ;
@@ -9,7 +8,7 @@ import { Camera, PageMeta } from "./camera";
98import { type ClientBridge , build as buildClientBridge } from "./client-bridge" ;
109import * as history from "./history" ;
1110import * as logger from "../utils/logger" ;
12- import { DEVTOOLS_PROTOCOL , WEBDRIVER_PROTOCOL } from "../constants/config" ;
11+ import { WEBDRIVER_PROTOCOL } from "../constants/config" ;
1312import { MIN_CHROME_VERSION_SUPPORT_ISOLATION } from "../constants/browser" ;
1413import { isSupportIsolation } from "../utils/browser" ;
1514import { isRunInNodeJsEnv } from "../utils/config" ;
@@ -19,8 +18,6 @@ import type { CalibrationResult, Calibrator } from "./calibrator";
1918import { NEW_ISSUE_LINK } from "../constants/help" ;
2019import { runWithoutHistory } from "./history" ;
2120import type { SessionOptions } from "./types" ;
22- import { Protocol } from "devtools-protocol" ;
23- import { getCalculatedProtocol } from "./commands/saveState" ;
2421import { Page } from "puppeteer-core" ;
2522import { CDP } from "./cdp" ;
2623import type { ElementReference } from "@testplane/wdio-protocols" ;
@@ -94,7 +91,6 @@ export class ExistingBrowser extends Browser {
9491 protected _calibration ?: CalibrationResult ;
9592 protected _clientBridge ?: ClientBridge ;
9693 protected _cdp : CDP | null = null ;
97- private _allCookies : Map < string , Protocol . Network . CookieParam > = new Map ( ) ;
9894
9995 constructor ( config : Config , opts : BrowserOpts ) {
10096 super ( config , opts ) ;
@@ -134,10 +130,6 @@ export class ExistingBrowser extends Browser {
134130
135131 await isolationPromise ;
136132
137- if ( getCalculatedProtocol ( this ) === DEVTOOLS_PROTOCOL ) {
138- await this . startCollectCookies ( ) ;
139- }
140-
141133 this . _callstackHistory ?. clear ( ) ;
142134
143135 try {
@@ -155,72 +147,6 @@ export class ExistingBrowser extends Browser {
155147 return this ;
156148 }
157149
158- getCookieIndex ( cookie : Cookie ) : string {
159- return [ cookie . name , cookie . domain , cookie . path ] . join ( "-" ) ;
160- }
161-
162- async getAllRequestsCookies ( ) : Promise < Array < Protocol . Network . CookieParam > > {
163- if ( this . _session ) {
164- const cookies = await this . _session . getAllCookies ( ) ;
165-
166- if ( cookies ) {
167- cookies . forEach ( cookie => {
168- this . _allCookies . set ( this . getCookieIndex ( cookie ) , cookie as Protocol . Network . CookieParam ) ;
169- } ) ;
170- }
171- }
172-
173- return [ ...this . _allCookies . values ( ) ] . map ( cookie => ( {
174- name : cookie . name ,
175- value : cookie . value ,
176- domain : cookie . domain ,
177- path : cookie . path ,
178- expires : cookie . expires ? cookie . expires : undefined ,
179- httpOnly : cookie . httpOnly ,
180- secure : cookie . secure ,
181- sameSite : cookie . sameSite ,
182- } ) ) ;
183- }
184-
185- async startCollectCookies ( ) : Promise < void > {
186- if ( ! this . _session ) {
187- return ;
188- }
189-
190- this . _allCookies = new Map ( ) ;
191-
192- const page = await getActivePuppeteerPage ( this . _session ) ;
193-
194- if ( ! page ) {
195- return ;
196- }
197-
198- page . on ( "response" , async res => {
199- try {
200- const headers = res . headers ( ) ;
201-
202- if ( headers [ "set-cookie" ] ) {
203- headers [ "set-cookie" ] . split ( "\n" ) . forEach ( str => {
204- parseCookiesString ( str , { map : false } ) . forEach ( ( cookie : Cookie ) => {
205- const index = this . getCookieIndex ( cookie ) ;
206- const expires = cookie . expires
207- ? Math . floor ( new Date ( cookie . expires ) . getTime ( ) / 1000 )
208- : undefined ;
209-
210- this . _allCookies . set ( index , {
211- ...cookie ,
212- domain : cookie . domain ?? new URL ( res . url ( ) ) . hostname ,
213- expires,
214- } as Protocol . Network . CookieParam ) ;
215- } ) ;
216- } ) ;
217- }
218- } catch ( err ) {
219- console . error ( err ) ;
220- }
221- } ) ;
222- }
223-
224150 markAsBroken ( ) : void {
225151 if ( this . state . isBroken ) {
226152 return ;
0 commit comments