forked from annv/MinigameTest
minigame
This commit is contained in:
194
node_modules/selenium-webdriver/bidi/browsingContext.js
generated
vendored
Normal file
194
node_modules/selenium-webdriver/bidi/browsingContext.js
generated
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
// Licensed to the Software Freedom Conservancy (SFC) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The SFC licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
class BrowsingContext {
|
||||
constructor(driver) {
|
||||
this._driver = driver
|
||||
}
|
||||
|
||||
async init({ browsingContextId, type, referenceContext }) {
|
||||
if (!(await this._driver.getCapabilities()).get('webSocketUrl')) {
|
||||
throw Error('WebDriver instance must support BiDi protocol')
|
||||
}
|
||||
|
||||
if (type != undefined && !['window', 'tab'].includes(type)) {
|
||||
throw Error(`Valid types are 'window' & 'tab'. Received: ${type}`)
|
||||
}
|
||||
|
||||
this.bidi = await this._driver.getBidi()
|
||||
this._id =
|
||||
browsingContextId == undefined
|
||||
? (await this.create(type, referenceContext))['result']['context']
|
||||
: browsingContextId
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a browsing context for the given type and referenceContext
|
||||
*/
|
||||
async create(type, referenceContext) {
|
||||
const params = {
|
||||
method: 'browsingContext.create',
|
||||
params: {
|
||||
type: type,
|
||||
referenceContext: referenceContext,
|
||||
},
|
||||
}
|
||||
return await this.bidi.send(params)
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns id
|
||||
*/
|
||||
get id() {
|
||||
return this._id
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url the url to navigate to
|
||||
* @param readinessState type of readiness state: "none" / "interactive" / "complete"
|
||||
* @returns NavigateResult object
|
||||
*/
|
||||
async navigate(url, readinessState = undefined) {
|
||||
if (
|
||||
readinessState != undefined &&
|
||||
!['none', 'interactive', 'complete'].includes(readinessState)
|
||||
) {
|
||||
throw Error(
|
||||
`Valid readiness states are 'none', 'interactive' & 'complete'. Received: ${readinessState}`
|
||||
)
|
||||
}
|
||||
|
||||
const params = {
|
||||
method: 'browsingContext.navigate',
|
||||
params: {
|
||||
context: this._id,
|
||||
url: url,
|
||||
wait: readinessState,
|
||||
},
|
||||
}
|
||||
const navigateResult = (await this.bidi.send(params))['result']
|
||||
|
||||
return new NavigateResult(
|
||||
navigateResult['url'],
|
||||
navigateResult['navigation']
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxDepth the max depth of the descendents of browsing context tree
|
||||
* @returns BrowsingContextInfo object
|
||||
*/
|
||||
async getTree(maxDepth = undefined) {
|
||||
const params = {
|
||||
method: 'browsingContext.getTree',
|
||||
params: {
|
||||
root: this._id,
|
||||
maxDepth: maxDepth,
|
||||
},
|
||||
}
|
||||
|
||||
let result = await this.bidi.send(params)
|
||||
if ('error' in result) {
|
||||
throw Error(result['error'])
|
||||
}
|
||||
|
||||
result = result['result']['contexts'][0]
|
||||
return new BrowsingContextInfo(
|
||||
result['context'],
|
||||
result['url'],
|
||||
result['children'],
|
||||
result['parent']
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the browing context
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async close() {
|
||||
const params = {
|
||||
method: 'browsingContext.close',
|
||||
params: {
|
||||
context: this._id,
|
||||
},
|
||||
}
|
||||
await this.bidi.send(params)
|
||||
}
|
||||
}
|
||||
|
||||
class NavigateResult {
|
||||
constructor(url, navigationId) {
|
||||
this._url = url
|
||||
this._navigationId = navigationId
|
||||
}
|
||||
|
||||
get url() {
|
||||
return this._url
|
||||
}
|
||||
|
||||
get navigationId() {
|
||||
return this._navigationId
|
||||
}
|
||||
}
|
||||
|
||||
class BrowsingContextInfo {
|
||||
constructor(id, url, children, parentBrowsingContext) {
|
||||
this._id = id
|
||||
this._url = url
|
||||
this._children = children
|
||||
this._parentBrowsingContext = parentBrowsingContext
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this._id
|
||||
}
|
||||
|
||||
get url() {
|
||||
return this._url
|
||||
}
|
||||
|
||||
get children() {
|
||||
return this._children
|
||||
}
|
||||
|
||||
get parentBrowsingContext() {
|
||||
return this._parentBrowsingContext
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* initiate browsing context instance and return
|
||||
* @param driver
|
||||
* @param browsingContextId The browsing context of current window/tab
|
||||
* @param type "window" or "tab"
|
||||
* @param referenceContext To get a browsing context for this reference if passed
|
||||
* @returns {Promise<BrowsingContext>}
|
||||
*/
|
||||
async function getBrowsingContextInstance(
|
||||
driver,
|
||||
{ browsingContextId, type, referenceContext }
|
||||
) {
|
||||
let instance = new BrowsingContext(driver)
|
||||
await instance.init({ browsingContextId, type, referenceContext })
|
||||
return instance
|
||||
}
|
||||
|
||||
/**
|
||||
* API
|
||||
* @type {function(*, {*,*,*}): Promise<BrowsingContext>}
|
||||
*/
|
||||
module.exports = getBrowsingContextInstance
|
||||
46
node_modules/selenium-webdriver/bidi/filterBy.js
generated
vendored
Normal file
46
node_modules/selenium-webdriver/bidi/filterBy.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
// Licensed to the Software Freedom Conservancy (SFC) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The SFC licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
class FilterBy {
|
||||
constructor(level) {
|
||||
this.level_ = level
|
||||
}
|
||||
|
||||
static logLevel(level) {
|
||||
if (
|
||||
level === undefined ||
|
||||
(level != undefined &&
|
||||
!['debug', 'error', 'info', 'warning'].includes(level))
|
||||
) {
|
||||
throw Error(
|
||||
`Please pass valid log level. Valid log levels are 'debug', 'error', 'info' and 'warning'. Received: ${level}`
|
||||
)
|
||||
}
|
||||
|
||||
return new FilterBy(level)
|
||||
}
|
||||
|
||||
getLevel() {
|
||||
return this.level_
|
||||
}
|
||||
}
|
||||
|
||||
// PUBLIC API
|
||||
|
||||
module.exports = {
|
||||
FilterBy,
|
||||
}
|
||||
224
node_modules/selenium-webdriver/bidi/index.js
generated
vendored
Normal file
224
node_modules/selenium-webdriver/bidi/index.js
generated
vendored
Normal file
@@ -0,0 +1,224 @@
|
||||
// Licensed to the Software Freedom Conservancy (SFC) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The SFC licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
const { EventEmitter } = require('node:events')
|
||||
const WebSocket = require('ws')
|
||||
|
||||
const RESPONSE_TIMEOUT = 1000 * 30
|
||||
|
||||
class Index extends EventEmitter {
|
||||
id = 0
|
||||
isConnected = false
|
||||
events = []
|
||||
browsingContexts = []
|
||||
|
||||
/**
|
||||
* Create a new websocket connection
|
||||
* @param _webSocketUrl
|
||||
*/
|
||||
constructor (_webSocketUrl) {
|
||||
super()
|
||||
this.isConnected = false
|
||||
this._ws = new WebSocket(_webSocketUrl)
|
||||
this._ws.on('open', () => {
|
||||
this.isConnected = true
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve connection
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
async waitForConnection () {
|
||||
return new Promise((resolve) => {
|
||||
if (this.isConnected) {
|
||||
resolve()
|
||||
} else {
|
||||
this._ws.once('open', () => {
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {WebSocket}
|
||||
*/
|
||||
get socket () {
|
||||
return this._ws
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean|*}
|
||||
*/
|
||||
get isConnected () {
|
||||
return this.isConnected
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a bidi request
|
||||
* @param params
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
async send (params) {
|
||||
if (!this.isConnected) {
|
||||
await this.waitForConnection()
|
||||
}
|
||||
|
||||
const id = ++this.id
|
||||
|
||||
this._ws.send(JSON.stringify({ id, ...params }))
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeoutId = setTimeout(() => {
|
||||
reject(new Error(`Request with id ${id} timed out`))
|
||||
handler.off('message', listener)
|
||||
}, RESPONSE_TIMEOUT)
|
||||
|
||||
const listener = (data) => {
|
||||
try {
|
||||
const payload = JSON.parse(data.toString())
|
||||
if (payload.id === id) {
|
||||
clearTimeout(timeoutId)
|
||||
handler.off('message', listener)
|
||||
resolve(payload)
|
||||
}
|
||||
} catch (err) {
|
||||
log.error(`Failed parse message: ${err.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handler = this._ws.on('message', listener)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to events
|
||||
* @param events
|
||||
* @param browsingContexts
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async subscribe (events, browsingContexts) {
|
||||
function toArray (arg) {
|
||||
if (arg === undefined) {
|
||||
return []
|
||||
}
|
||||
|
||||
return Array.isArray(arg) ? [...arg] : [arg]
|
||||
}
|
||||
|
||||
const eventsArray = toArray(events)
|
||||
const contextsArray = toArray(browsingContexts)
|
||||
|
||||
const params = {
|
||||
method: 'session.subscribe', params: {},
|
||||
}
|
||||
|
||||
if (eventsArray.length && eventsArray.some(
|
||||
event => typeof event !== 'string')) {
|
||||
throw new TypeError('events should be string or string array')
|
||||
}
|
||||
|
||||
if (contextsArray.length && contextsArray.some(
|
||||
context => typeof context !== 'string')) {
|
||||
throw new TypeError('browsingContexts should be string or string array')
|
||||
}
|
||||
|
||||
if (eventsArray.length) {
|
||||
params.params.events = eventsArray
|
||||
}
|
||||
|
||||
if (contextsArray.length) {
|
||||
params.params.contexts = contextsArray
|
||||
}
|
||||
|
||||
await this.send(params)
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe to events
|
||||
* @param events
|
||||
* @param browsingContexts
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async unsubscribe (events, browsingContexts) {
|
||||
if (typeof events === 'string') {
|
||||
this.events = this.events.filter(event => event !== events)
|
||||
} else if (Array.isArray(events)) {
|
||||
this.events = this.events.filter(event => !events.includes(event))
|
||||
}
|
||||
|
||||
if (typeof browsingContexts === 'string') {
|
||||
this.browsingContexts.pop()
|
||||
} else if (Array.isArray(browsingContexts)) {
|
||||
this.browsingContexts =
|
||||
this.browsingContexts.filter(id => !browsingContexts.includes(id))
|
||||
}
|
||||
|
||||
const params = {
|
||||
method: 'session.unsubscribe', params: {
|
||||
events: this.events,
|
||||
}
|
||||
}
|
||||
|
||||
if (this.browsingContexts.length > 0) {
|
||||
params.params.contexts = this.browsingContexts
|
||||
}
|
||||
|
||||
await this.send(params)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Bidi Status
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
get status () {
|
||||
return this.send({
|
||||
method: 'session.status', params: {}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Close ws connection.
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
close () {
|
||||
const closeWebSocket = (callback) => {
|
||||
// don't close if it's already closed
|
||||
if (this._ws.readyState === 3) {
|
||||
callback()
|
||||
} else {
|
||||
// don't notify on user-initiated shutdown ('disconnect' event)
|
||||
this._ws.removeAllListeners('close')
|
||||
this._ws.once('close', () => {
|
||||
this._ws.removeAllListeners()
|
||||
callback()
|
||||
})
|
||||
this._ws.close()
|
||||
}
|
||||
}
|
||||
return new Promise((fulfill, reject) => {
|
||||
closeWebSocket(fulfill)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API
|
||||
* @type {function(*): Promise<Index>}
|
||||
*/
|
||||
module.exports = Index
|
||||
87
node_modules/selenium-webdriver/bidi/logEntries.js
generated
vendored
Normal file
87
node_modules/selenium-webdriver/bidi/logEntries.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
// Licensed to the Software Freedom Conservancy (SFC) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The SFC licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
'use strict'
|
||||
|
||||
class BaseLogEntry {
|
||||
constructor (level, text, timeStamp, stackTrace) {
|
||||
this._level = level
|
||||
this._text = text
|
||||
this._timeStamp = timeStamp
|
||||
this._stackTrace = stackTrace
|
||||
}
|
||||
|
||||
get level () {
|
||||
return this._level
|
||||
}
|
||||
|
||||
get text () {
|
||||
return this._text
|
||||
}
|
||||
|
||||
get timeStamp () {
|
||||
return this._timeStamp
|
||||
}
|
||||
|
||||
get stackTrace () {
|
||||
return this._stackTrace
|
||||
}
|
||||
}
|
||||
|
||||
class GenericLogEntry extends BaseLogEntry {
|
||||
constructor (level, text, timeStamp, type, stackTrace) {
|
||||
super(level, text, timeStamp, stackTrace)
|
||||
this._type = type
|
||||
}
|
||||
|
||||
get type () {
|
||||
return this._type
|
||||
}
|
||||
}
|
||||
|
||||
class ConsoleLogEntry extends GenericLogEntry {
|
||||
constructor (level, text, timeStamp, type, method, realm, args, stackTrace) {
|
||||
super(level, text, timeStamp, type, stackTrace)
|
||||
this._method = method
|
||||
this._realm = realm
|
||||
this._args = args
|
||||
}
|
||||
|
||||
get method () {
|
||||
return this._method
|
||||
}
|
||||
|
||||
get realm () {
|
||||
return this._realm
|
||||
}
|
||||
|
||||
get args () {
|
||||
return this._args
|
||||
}
|
||||
}
|
||||
|
||||
class JavascriptLogEntry extends GenericLogEntry {
|
||||
constructor (level, text, timeStamp, type, stackTrace) {
|
||||
super(level, text, timeStamp, type, stackTrace)
|
||||
}
|
||||
}
|
||||
|
||||
// PUBLIC API
|
||||
|
||||
module.exports = {
|
||||
BaseLogEntry, GenericLogEntry, ConsoleLogEntry, JavascriptLogEntry,
|
||||
}
|
||||
269
node_modules/selenium-webdriver/bidi/logInspector.js
generated
vendored
Normal file
269
node_modules/selenium-webdriver/bidi/logInspector.js
generated
vendored
Normal file
@@ -0,0 +1,269 @@
|
||||
// Licensed to the Software Freedom Conservancy (SFC) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The SFC licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
const { FilterBy } = require('./filterBy')
|
||||
const { ConsoleLogEntry, JavascriptLogEntry, GenericLogEntry } = require('./logEntries')
|
||||
|
||||
const LOG = {
|
||||
TYPE_CONSOLE : 'console',
|
||||
TYPE_JS_LOGS : 'javascript',
|
||||
}
|
||||
|
||||
class LogInspector {
|
||||
bidi
|
||||
ws
|
||||
|
||||
constructor (driver, browsingContextIds) {
|
||||
this._driver = driver
|
||||
this._browsingContextIds = browsingContextIds
|
||||
this.listener = {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to log event
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async init () {
|
||||
this.bidi = await this._driver.getBidi()
|
||||
await this.bidi.subscribe('log.entryAdded', this._browsingContextIds)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param kind
|
||||
*/
|
||||
logListener (kind) {
|
||||
if (!(kind in this.listener)) {
|
||||
this.listener[kind] = []
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to Console logs
|
||||
* @param callback
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async onConsoleEntry(callback, filterBy = undefined) {
|
||||
if (filterBy != undefined && !(filterBy instanceof FilterBy)) {
|
||||
throw Error(`Pass valid FilterBy object. Received: ${filterBy}`)
|
||||
}
|
||||
|
||||
this.ws = await this.bidi.socket
|
||||
|
||||
this.ws.on('message', (event) => {
|
||||
const { params } = JSON.parse(Buffer.from(event.toString()))
|
||||
|
||||
if (params?.type === LOG.TYPE_CONSOLE) {
|
||||
let consoleEntry = new ConsoleLogEntry(
|
||||
params.level,
|
||||
params.text,
|
||||
params.timestamp,
|
||||
params.type,
|
||||
params.method,
|
||||
params.realm,
|
||||
params.args,
|
||||
params.stackTrace
|
||||
)
|
||||
|
||||
if (filterBy != undefined) {
|
||||
if (params?.level === filterBy.getLevel()) {
|
||||
callback(consoleEntry)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
callback(consoleEntry)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to JS logs
|
||||
* @param callback
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async onJavascriptLog(callback, filterBy = undefined) {
|
||||
if (filterBy != undefined && !(filterBy instanceof FilterBy)) {
|
||||
throw Error(`Pass valid FilterBy object. Received: ${filterBy}`)
|
||||
}
|
||||
|
||||
this.ws = await this.bidi.socket
|
||||
|
||||
this.ws.on('message', (event) => {
|
||||
const { params } = JSON.parse(Buffer.from(event.toString()))
|
||||
|
||||
if (params?.type === LOG.TYPE_JS_LOGS) {
|
||||
let jsEntry = new JavascriptLogEntry(
|
||||
params.level,
|
||||
params.text,
|
||||
params.timestamp,
|
||||
params.type,
|
||||
params.stackTrace
|
||||
)
|
||||
|
||||
if (filterBy != undefined) {
|
||||
if (params?.level === filterBy.getLevel()) {
|
||||
callback(jsEntry)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
callback(jsEntry)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to JS Exceptions
|
||||
* @param callback
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async onJavascriptException(callback) {
|
||||
this.ws = await this.bidi.socket
|
||||
let enabled =
|
||||
LOG.TYPE_JS_EXCEPTION in this.listener ||
|
||||
this.logListener(LOG.TYPE_JS_EXCEPTION)
|
||||
this.listener[LOG.TYPE_JS_EXCEPTION].push(callback)
|
||||
|
||||
if (enabled) {
|
||||
return
|
||||
}
|
||||
|
||||
this.ws.on('message', (event) => {
|
||||
const { params } = JSON.parse(Buffer.from(event.toString()))
|
||||
if (params?.type === 'javascript' && params?.level === 'error') {
|
||||
let jsErrorEntry = new JavascriptLogEntry(
|
||||
params.level,
|
||||
params.text,
|
||||
params.timestamp,
|
||||
params.type,
|
||||
params.stackTrace
|
||||
)
|
||||
|
||||
this.listener[LOG.TYPE_JS_EXCEPTION].forEach((listener) => {
|
||||
listener(jsErrorEntry)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to any logs
|
||||
* @param callback
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async onLog(callback, filterBy = undefined) {
|
||||
if (filterBy != undefined && !(filterBy instanceof FilterBy)) {
|
||||
throw Error(`Pass valid FilterBy object. Received: ${filterBy}`)
|
||||
}
|
||||
|
||||
this.ws = await this.bidi.socket
|
||||
|
||||
this.ws.on('message', (event) => {
|
||||
const { params } = JSON.parse(Buffer.from(event.toString()))
|
||||
if (params?.type === 'javascript') {
|
||||
let jsEntry = new JavascriptLogEntry(
|
||||
params.level,
|
||||
params.text,
|
||||
params.timestamp,
|
||||
params.type,
|
||||
params.stackTrace
|
||||
)
|
||||
|
||||
if (filterBy != undefined) {
|
||||
if (params?.level === filterBy.getLevel()) {
|
||||
callback(jsEntry)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
callback(jsEntry)
|
||||
return
|
||||
}
|
||||
|
||||
if (params?.type === 'console') {
|
||||
let consoleEntry = new ConsoleLogEntry(
|
||||
params.level,
|
||||
params.text,
|
||||
params.timestamp,
|
||||
params.type,
|
||||
params.method,
|
||||
params.realm,
|
||||
params.args,
|
||||
params.stackTrace
|
||||
)
|
||||
|
||||
if (filterBy != undefined) {
|
||||
if (params?.level === filterBy.getLevel()) {
|
||||
callback(consoleEntry)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
callback(consoleEntry)
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
params != undefined &&
|
||||
!['console', 'javascript'].includes(params?.type)
|
||||
) {
|
||||
let genericEntry = new GenericLogEntry(
|
||||
params.level,
|
||||
params.text,
|
||||
params.timestamp,
|
||||
params.type,
|
||||
params.stackTrace
|
||||
)
|
||||
|
||||
if (filterBy != undefined) {
|
||||
if (params?.level === filterBy.getLevel()) {
|
||||
callback(genericEntry)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
callback(genericEntry)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe to log event
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async close () {
|
||||
await this.bidi.unsubscribe('log.entryAdded', this._browsingContextIds)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* initiate inspector instance and return
|
||||
* @param driver
|
||||
* @param browsingContextIds
|
||||
* @returns {Promise<LogInspector>}
|
||||
*/
|
||||
async function getLogInspectorInstance (driver, browsingContextIds) {
|
||||
let instance = new LogInspector(driver, browsingContextIds)
|
||||
await instance.init()
|
||||
return instance
|
||||
}
|
||||
|
||||
/**
|
||||
* API
|
||||
* @type {function(*, *): Promise<LogInspector>}
|
||||
*/
|
||||
module.exports = getLogInspectorInstance
|
||||
Reference in New Issue
Block a user