Comparing version 0.0.4-alpha-13 to 0.0.4-alpha-14
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Storage = exports.Session = exports.Log = exports.Input = exports.BrowsingContext = exports.Browser = exports.BiDi = void 0; | ||
exports.Storage = exports.Session = exports.Network = exports.Log = exports.Input = exports.BrowsingContext = exports.Browser = exports.BiDi = void 0; | ||
const ws_1 = __importDefault(require("ws")); | ||
@@ -31,2 +31,4 @@ const node_timers_1 = require("node:timers"); | ||
exports.Storage = commands_6.default; | ||
const commands_7 = __importDefault(require("./modules/network/commands")); | ||
exports.Network = commands_7.default; | ||
const RESPONSE_TIMEOUT = 60 * 1000; | ||
@@ -33,0 +35,0 @@ /** |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Network class provides methods to manage network requests and responses | ||
* using BiDi (Bidirectional) communication. | ||
*/ | ||
class Network { | ||
/** | ||
* Constructs a new Network instance. | ||
* @param BidiConnection - The BiDi connection instance. | ||
*/ | ||
constructor(BidiConnection) { | ||
this._ws = BidiConnection; | ||
} | ||
/** | ||
* Adds a network intercept. | ||
* @param context - The parameters for adding the network intercept. | ||
* @returns A promise that resolves with the result of adding the network intercept. | ||
*/ | ||
addIntercept(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.addIntercept', | ||
params: context | ||
}; | ||
return new Promise((resolve, reject) => { | ||
this._ws.sendCommand(param) | ||
.then(response => resolve(response)) | ||
.catch(error => reject(`Failed to intercept network ${error}`)); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Continues a paused network request. | ||
* @param context - The parameters for continuing the network request. | ||
* @returns A promise that resolves when the request is continued. | ||
*/ | ||
continueRequest(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.continueRequest', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
/** | ||
* Continues a paused network response. | ||
* @param context - The parameters for continuing the network response. | ||
* @returns A promise that resolves when the response is continued. | ||
*/ | ||
continueResponse(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.continueResponse', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
/** | ||
* Continues a paused network request with authentication. | ||
* @param context - The parameters for continuing the network request with authentication. | ||
* @returns A promise that resolves when the request is continued with authentication. | ||
*/ | ||
continueWithAuth(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.continueWithAuth', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
/** | ||
* Fails a network request. | ||
* @param context - The parameters for failing the network request. | ||
* @returns A promise that resolves when the request is failed. | ||
*/ | ||
failRequest(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.failRequest', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
/** | ||
* Provides a response to a network request. | ||
* @param context - The parameters for providing the network response. | ||
* @returns A promise that resolves when the response is provided. | ||
*/ | ||
provideResponse(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.provideResponse', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
/** | ||
* Removes a network intercept. | ||
* @param context - The parameters for removing the network intercept. | ||
* @returns A promise that resolves when the network intercept is removed. | ||
*/ | ||
removeIntercept(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.removeIntercept', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
/** | ||
* Configures the network cache behavior for certain requests. | ||
* @param context - The parameters for setting the cache behavior. | ||
* @returns A promise that resolves when the cache behavior is set. | ||
*/ | ||
setCacheBehavior(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.setCacheBehavior', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
} | ||
exports.default = Network; |
@@ -18,2 +18,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import Storage from './modules/storage/commands'; | ||
import Network from "./modules/network/commands"; | ||
const RESPONSE_TIMEOUT = 60 * 1000; | ||
@@ -134,2 +135,2 @@ /** | ||
} | ||
export { BiDi, Browser, BrowsingContext, Input, Log, Session, Storage }; | ||
export { BiDi, Browser, BrowsingContext, Input, Log, Network, Session, Storage }; |
@@ -1,1 +0,138 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
/** | ||
* Network class provides methods to manage network requests and responses | ||
* using BiDi (Bidirectional) communication. | ||
*/ | ||
export default class Network { | ||
/** | ||
* Constructs a new Network instance. | ||
* @param BidiConnection - The BiDi connection instance. | ||
*/ | ||
constructor(BidiConnection) { | ||
this._ws = BidiConnection; | ||
} | ||
/** | ||
* Adds a network intercept. | ||
* @param context - The parameters for adding the network intercept. | ||
* @returns A promise that resolves with the result of adding the network intercept. | ||
*/ | ||
addIntercept(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.addIntercept', | ||
params: context | ||
}; | ||
return new Promise((resolve, reject) => { | ||
this._ws.sendCommand(param) | ||
.then(response => resolve(response)) | ||
.catch(error => reject(`Failed to intercept network ${error}`)); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Continues a paused network request. | ||
* @param context - The parameters for continuing the network request. | ||
* @returns A promise that resolves when the request is continued. | ||
*/ | ||
continueRequest(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.continueRequest', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
/** | ||
* Continues a paused network response. | ||
* @param context - The parameters for continuing the network response. | ||
* @returns A promise that resolves when the response is continued. | ||
*/ | ||
continueResponse(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.continueResponse', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
/** | ||
* Continues a paused network request with authentication. | ||
* @param context - The parameters for continuing the network request with authentication. | ||
* @returns A promise that resolves when the request is continued with authentication. | ||
*/ | ||
continueWithAuth(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.continueWithAuth', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
/** | ||
* Fails a network request. | ||
* @param context - The parameters for failing the network request. | ||
* @returns A promise that resolves when the request is failed. | ||
*/ | ||
failRequest(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.failRequest', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
/** | ||
* Provides a response to a network request. | ||
* @param context - The parameters for providing the network response. | ||
* @returns A promise that resolves when the response is provided. | ||
*/ | ||
provideResponse(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.provideResponse', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
/** | ||
* Removes a network intercept. | ||
* @param context - The parameters for removing the network intercept. | ||
* @returns A promise that resolves when the network intercept is removed. | ||
*/ | ||
removeIntercept(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.removeIntercept', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
/** | ||
* Configures the network cache behavior for certain requests. | ||
* @param context - The parameters for setting the cache behavior. | ||
* @returns A promise that resolves when the cache behavior is set. | ||
*/ | ||
setCacheBehavior(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const param = { | ||
method: 'network.setCacheBehavior', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(param); | ||
}); | ||
} | ||
} |
@@ -8,2 +8,3 @@ import WebSocket from 'ws'; | ||
import Storage from './modules/storage/commands'; | ||
import Network from "./modules/network/commands"; | ||
/** | ||
@@ -48,2 +49,2 @@ * BiDi class for handling WebSocket connections | ||
} | ||
export { BiDi, Browser, BrowsingContext, Input, Log, Session, Storage }; | ||
export { BiDi, Browser, BrowsingContext, Input, Log, Network, Session, Storage }; |
@@ -0,2 +1,6 @@ | ||
import { BrowsingContext, Navigation } from "../browsingContext/types"; | ||
import { ScriptStackTrace } from "../script/types"; | ||
export type NetworkSameSite = 'strict' | 'lax' | 'none'; | ||
type NetworkIntercept = string; | ||
type NetworkRequest = string; | ||
export interface NetworkCookie { | ||
@@ -13,2 +17,6 @@ name: string; | ||
} | ||
export interface NetworkCookieHeader { | ||
name: string; | ||
value: NetworkBytesValue; | ||
} | ||
export type NetworkBytesValue = StringValue | Base64Value; | ||
@@ -23,2 +31,185 @@ type StringValue = { | ||
}; | ||
export interface NetworkAuthChallenge { | ||
scheme: string; | ||
realm: string; | ||
} | ||
export interface NetworkAuthCredentials { | ||
type: 'password'; | ||
username: string; | ||
password: string; | ||
} | ||
export interface NetWorkBaseParameters { | ||
context: BrowsingContext | null; | ||
isBlocked: boolean; | ||
navigation: Navigation | null; | ||
redirectCount: number; | ||
request: NetworkRequestData; | ||
timestamp: number; | ||
intercepts?: NetworkIntercept[]; | ||
} | ||
export interface NetworkRequestData { | ||
request: NetworkRequest; | ||
url: string; | ||
method: string; | ||
headers: NetworkHeader[]; | ||
cookies: NetworkCookie[]; | ||
headerSize: number; | ||
bodySize: number; | ||
timings: NetworkFetchTimingInfo; | ||
} | ||
export interface NetworkCookie { | ||
name: string; | ||
value: NetworkBytesValue; | ||
domain: string; | ||
path: string; | ||
size: number; | ||
httpOnly: boolean; | ||
secure: boolean; | ||
sameSite: NetworkSameSite; | ||
} | ||
export interface NetworkFetchTimingInfo { | ||
timeOrigin: number; | ||
requestTime: number; | ||
redirectStart: number; | ||
redirectEnd: number; | ||
fetchStart: number; | ||
dnsStart: number; | ||
dnsEnd: number; | ||
connectStart: number; | ||
connectEnd: number; | ||
tlsStart: number; | ||
requestStart: number; | ||
responseStart: number; | ||
responseEnd: number; | ||
} | ||
export interface NetworkHeader { | ||
name: string; | ||
value: NetworkBytesValue; | ||
} | ||
export interface NetworkInitiator { | ||
type: 'parser' | 'script' | 'preflight' | 'other'; | ||
columnNumber?: number; | ||
lineNumber?: number; | ||
stackTrace?: ScriptStackTrace; | ||
request?: NetworkRequest; | ||
} | ||
export interface NetworkResponseContent { | ||
size: number; | ||
} | ||
export interface NetworkResponseData { | ||
url: string; | ||
protocol: string; | ||
status: number; | ||
statusText: string; | ||
fromCache: boolean; | ||
headers: NetworkHeader[]; | ||
mimeType: string; | ||
bytesReceived: number; | ||
headerSize: number | null; | ||
bodySize: number | null; | ||
content: NetworkResponseContent; | ||
authChallenges?: NetworkAuthChallenge[]; | ||
} | ||
export interface NetworkSetCookieHeader { | ||
name: string; | ||
value: NetworkBytesValue; | ||
domain?: string; | ||
httpOnly?: boolean; | ||
expiry?: string; | ||
maxAge?: number; | ||
path?: string; | ||
sameSite?: NetworkSameSite; | ||
secure?: boolean; | ||
} | ||
export type NetworkUrlPattern = NetworkUrlPatternPattern | NetworkUrlPatternString; | ||
export interface NetworkUrlPatternPattern { | ||
type: 'pattern'; | ||
protocol?: string; | ||
hostname?: string; | ||
port?: string; | ||
pathname?: string; | ||
search?: string; | ||
} | ||
export interface NetworkUrlPatternString { | ||
type: 'string'; | ||
pattern: string; | ||
} | ||
export interface NetworkAddIntercept { | ||
method: 'network.addIntercept'; | ||
params: NetworkAddInterceptParameters; | ||
} | ||
export interface NetworkAddInterceptParameters { | ||
phases: NetworkInterceptPhase[]; | ||
contexts?: BrowsingContext[]; | ||
urlPatterns?: NetworkUrlPattern[]; | ||
} | ||
export type NetworkInterceptPhase = 'beforeRequestSent' | 'responseStarted' | 'authRequired'; | ||
export interface NetworkAddInterceptResult { | ||
intercept: NetworkIntercept; | ||
} | ||
export interface NetworkContinueRequest { | ||
method: 'network.continueRequest'; | ||
params: NetworkContinueRequestParameters; | ||
} | ||
export interface NetworkContinueRequestParameters { | ||
request: NetworkRequest; | ||
body?: NetworkBytesValue; | ||
cookies?: NetworkCookieHeader[]; | ||
headers?: NetworkHeader[]; | ||
method?: string; | ||
url?: string; | ||
} | ||
export interface NetworkContinueResponse { | ||
method: 'network.continueResponse'; | ||
params: NetworkContinueResponseParameters; | ||
} | ||
export interface NetworkContinueResponseParameters { | ||
request: NetworkRequest; | ||
cookies?: NetworkSetCookieHeader[]; | ||
credentials?: NetworkAuthCredentials; | ||
headers?: NetworkHeader[]; | ||
reasonPhrase?: string; | ||
statusCode?: number; | ||
} | ||
export interface NetworkContinueWithAuth { | ||
method: 'network.continueWithAuth'; | ||
params: NetworkContinueWithAuthParameters; | ||
} | ||
export interface NetworkContinueWithAuthParameters { | ||
request: NetworkRequest; | ||
} | ||
export interface NetworkContinueWithAuthCredentials { | ||
action: 'provideCredentials'; | ||
credentials: NetworkAuthCredentials; | ||
} | ||
export interface NetworkContinueWithAuthNoCredentials { | ||
action: 'default' | 'cancel'; | ||
} | ||
export interface NetworkFailRequest { | ||
method: 'network.failRequest'; | ||
params: NetworkFailRequestParameters; | ||
} | ||
export interface NetworkFailRequestParameters { | ||
request: NetworkRequest; | ||
} | ||
export interface NetworkProvideResponse { | ||
method: 'network.provideResponse'; | ||
params: NetworkProvideResponseParameters; | ||
} | ||
export type NetworkProvideResponseParameters = NetworkContinueResponseParameters; | ||
export interface NetworkRemoveIntercept { | ||
method: 'network.removeIntercept'; | ||
params: NetworkRemoveInterceptParameters; | ||
} | ||
export interface NetworkRemoveInterceptParameters { | ||
intercept: NetworkIntercept; | ||
} | ||
export interface NetworkSetCacheBehavior { | ||
method: 'network.setCacheBehavior'; | ||
params: NetworkSetCacheBehaviorParameters; | ||
} | ||
export interface NetworkSetCacheBehaviorParameters { | ||
cacheBehaviour: 'default' | 'bypass'; | ||
contexts: BrowsingContext[]; | ||
} | ||
export {}; |
@@ -141,2 +141,11 @@ import { BrowsingContext } from "../browsingContext/types"; | ||
}; | ||
export interface ScriptStackTrace { | ||
callFrames: ScriptStackFrame[]; | ||
} | ||
export interface ScriptStackFrame { | ||
columnNumber: number; | ||
functionName: string; | ||
lineNumber: number; | ||
url: string; | ||
} | ||
export {}; |
{ | ||
"name": "wd-bidi", | ||
"version": "0.0.4-alpha-13", | ||
"version": "0.0.4-alpha-14", | ||
"description": "WebDriver BiDi API for automation testing", | ||
@@ -42,15 +42,15 @@ "main": "./build/cjs/index.js", | ||
"devDependencies": { | ||
"@eslint/js": "^9.7.0", | ||
"@types/node": "^20.14.10", | ||
"@eslint/js": "^9.8.0", | ||
"@types/node": "^20.14.12", | ||
"@types/ws": "^8.5.11", | ||
"@typescript-eslint/eslint-plugin": "^7.16.0", | ||
"@typescript-eslint/parser": "^7.16.0", | ||
"@typescript-eslint/eslint-plugin": "^7.17.0", | ||
"@typescript-eslint/parser": "^7.17.0", | ||
"eslint": "^8.57.0 ", | ||
"globals": "^15.8.0", | ||
"rimraf": "^6.0.1", | ||
"typedoc": "^0.26.4", | ||
"typescript": "^5.5.3", | ||
"typescript-eslint": "^7.16.0", | ||
"typedoc": "^0.26.5", | ||
"typescript": "^5.5.4", | ||
"typescript-eslint": "^7.17.0", | ||
"ws": "^8.18.0" | ||
} | ||
} |
# wd-bidi | ||
package for implementing [webdriver BIDI](https://w3c.github.io/webdriver-bidi/). | ||
The alpha-4 has basic class to create, subscribe and listen to events. Currently, the development of this package is ongoing and the next release will | ||
The alpha has basic class to create, subscribe and listen to events. Currently, the development of this package is ongoing and the next release will | ||
include a simple API for subscribing to and listening to multiple events. | ||
@@ -6,0 +6,0 @@ This will make it easier for developers to interact with the WebDriver BIDI |
151804
3641
77