-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(network): fetch content data as long as exists target session (#25)
closes #24
- Loading branch information
Showing
11 changed files
with
283 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
export { CRIConnection } from './CRIConnection'; | ||
export { | ||
CRIConnection, | ||
ChromeRemoteInterfaceEvent, | ||
ChromeRemoteInterfaceMethod | ||
} from './CRIConnection'; | ||
export { RetryStrategy } from './RetryStrategy'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { NetworkRequest } from './NetworkRequest'; | ||
import { Header } from 'har-format'; | ||
|
||
export interface RequestExtraInfo { | ||
requestHeaders: Header[]; | ||
} | ||
|
||
export interface ResponseExtraInfo { | ||
responseHeaders: Header[]; | ||
responseHeadersText: string; | ||
} | ||
|
||
export class ExtraInfoBuilder { | ||
private _hasExtraInfo: boolean = false; | ||
private _finished: boolean = false; | ||
private readonly _requests: NetworkRequest[] = []; | ||
private readonly _requestExtraInfo: RequestExtraInfo[] = []; | ||
private readonly _responseExtraInfo: ResponseExtraInfo[] = []; | ||
|
||
constructor(private readonly deleteCallback: () => void) {} | ||
|
||
public addRequestExtraInfo(info: RequestExtraInfo): void { | ||
this._requestExtraInfo.push(info); | ||
this.sync(); | ||
} | ||
|
||
public addResponseExtraInfo(info: ResponseExtraInfo): void { | ||
this._responseExtraInfo.push(info); | ||
this.sync(); | ||
} | ||
|
||
public finished(): void { | ||
this._finished = true; | ||
this.deleteIfComplete(); | ||
} | ||
|
||
private deleteIfComplete(): void { | ||
if (!this._finished) { | ||
return; | ||
} | ||
|
||
if (this._hasExtraInfo) { | ||
const lastRequest: NetworkRequest | undefined = this.getLastRequest(); | ||
|
||
if (!lastRequest?.hasExtraResponseInfo) { | ||
return; | ||
} | ||
} | ||
|
||
this.deleteCallback(); | ||
} | ||
|
||
private getLastRequest(): NetworkRequest | undefined { | ||
return this._requests[this._requests.length - 1]; | ||
} | ||
|
||
private getRequestIndex(req: NetworkRequest): number | undefined { | ||
return this._requests.indexOf(req); | ||
} | ||
|
||
private sync(): void { | ||
const req: NetworkRequest | undefined = this.getLastRequest(); | ||
|
||
if (!req) { | ||
return; | ||
} | ||
|
||
const index: number | undefined = this.getRequestIndex(req); | ||
|
||
const requestExtraInfo: RequestExtraInfo | undefined = this | ||
._requestExtraInfo[index]; | ||
|
||
if (requestExtraInfo) { | ||
req.addExtraRequestInfo(requestExtraInfo); | ||
this._requestExtraInfo[index] = null; | ||
} | ||
|
||
const responseExtraInfo: ResponseExtraInfo | undefined = this | ||
._responseExtraInfo[index]; | ||
if (responseExtraInfo) { | ||
req.addExtraResponseInfo(responseExtraInfo); | ||
this._responseExtraInfo[index] = null; | ||
} | ||
|
||
this.deleteIfComplete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.