How to use _onLoadingStopped method in Puppeteer

Best JavaScript code snippet using puppeteer

FrameManager.js

Source:FrameManager.js Github

copy

Full Screen

...124 _onFrameStoppedLoading(frameId) {125 const frame = this._frames.get(frameId);126 if (!frame)127 return;128 frame._onLoadingStopped();129 this.emit(Events_1.Events.FrameManager.LifecycleEvent, frame);130 }131 _handleFrameTree(frameTree) {132 if (frameTree.frame.parentId)133 this._onFrameAttached(frameTree.frame.id, frameTree.frame.parentId);134 this._onFrameNavigated(frameTree.frame);135 if (!frameTree.childFrames)136 return;137 for (const child of frameTree.childFrames)138 this._handleFrameTree(child);139 }140 page() {141 return this._page;142 }143 mainFrame() {144 return this._mainFrame;145 }146 frames() {147 return Array.from(this._frames.values());148 }149 frame(frameId) {150 return this._frames.get(frameId) || null;151 }152 _onFrameAttached(frameId, parentFrameId) {153 if (this._frames.has(frameId))154 return;155 helper_1.assert(parentFrameId);156 const parentFrame = this._frames.get(parentFrameId);157 const frame = new Frame(this, this._client, parentFrame, frameId);158 this._frames.set(frame._id, frame);159 this.emit(Events_1.Events.FrameManager.FrameAttached, frame);160 }161 _onFrameNavigated(framePayload) {162 const isMainFrame = !framePayload.parentId;163 let frame = isMainFrame164 ? this._mainFrame165 : this._frames.get(framePayload.id);166 helper_1.assert(isMainFrame || frame, 'We either navigate top level or have old version of the navigated frame');167 // Detach all child frames first.168 if (frame) {169 for (const child of frame.childFrames())170 this._removeFramesRecursively(child);171 }172 // Update or create main frame.173 if (isMainFrame) {174 if (frame) {175 // Update frame id to retain frame identity on cross-process navigation.176 this._frames.delete(frame._id);177 frame._id = framePayload.id;178 }179 else {180 // Initial main frame navigation.181 frame = new Frame(this, this._client, null, framePayload.id);182 }183 this._frames.set(framePayload.id, frame);184 this._mainFrame = frame;185 }186 // Update frame payload.187 frame._navigated(framePayload);188 this.emit(Events_1.Events.FrameManager.FrameNavigated, frame);189 }190 async _ensureIsolatedWorld(name) {191 if (this._isolatedWorlds.has(name))192 return;193 this._isolatedWorlds.add(name);194 await this._client.send('Page.addScriptToEvaluateOnNewDocument', {195 source: `//# sourceURL=${ExecutionContext_1.EVALUATION_SCRIPT_URL}`,196 worldName: name,197 }),198 await Promise.all(this.frames().map((frame) => this._client199 .send('Page.createIsolatedWorld', {200 frameId: frame._id,201 grantUniveralAccess: true,202 worldName: name,203 })204 .catch(helper_1.debugError))); // frames might be removed before we send this205 }206 _onFrameNavigatedWithinDocument(frameId, url) {207 const frame = this._frames.get(frameId);208 if (!frame)209 return;210 frame._navigatedWithinDocument(url);211 this.emit(Events_1.Events.FrameManager.FrameNavigatedWithinDocument, frame);212 this.emit(Events_1.Events.FrameManager.FrameNavigated, frame);213 }214 _onFrameDetached(frameId) {215 const frame = this._frames.get(frameId);216 if (frame)217 this._removeFramesRecursively(frame);218 }219 _onExecutionContextCreated(contextPayload) {220 const auxData = contextPayload.auxData;221 const frameId = auxData ? auxData.frameId : null;222 const frame = this._frames.get(frameId) || null;223 let world = null;224 if (frame) {225 if (contextPayload.auxData && !!contextPayload.auxData['isDefault']) {226 world = frame._mainWorld;227 }228 else if (contextPayload.name === UTILITY_WORLD_NAME &&229 !frame._secondaryWorld._hasContext()) {230 // In case of multiple sessions to the same target, there's a race between231 // connections so we might end up creating multiple isolated worlds.232 // We can use either.233 world = frame._secondaryWorld;234 }235 }236 if (contextPayload.auxData && contextPayload.auxData['type'] === 'isolated')237 this._isolatedWorlds.add(contextPayload.name);238 const context = new ExecutionContext_1.ExecutionContext(this._client, contextPayload, world);239 if (world)240 world._setContext(context);241 this._contextIdToContext.set(contextPayload.id, context);242 }243 /**244 * @param {number} executionContextId245 */246 _onExecutionContextDestroyed(executionContextId) {247 const context = this._contextIdToContext.get(executionContextId);248 if (!context)249 return;250 this._contextIdToContext.delete(executionContextId);251 if (context._world)252 context._world._setContext(null);253 }254 _onExecutionContextsCleared() {255 for (const context of this._contextIdToContext.values()) {256 if (context._world)257 context._world._setContext(null);258 }259 this._contextIdToContext.clear();260 }261 executionContextById(contextId) {262 const context = this._contextIdToContext.get(contextId);263 helper_1.assert(context, 'INTERNAL ERROR: missing context with id = ' + contextId);264 return context;265 }266 _removeFramesRecursively(frame) {267 for (const child of frame.childFrames())268 this._removeFramesRecursively(child);269 frame._detach();270 this._frames.delete(frame._id);271 this.emit(Events_1.Events.FrameManager.FrameDetached, frame);272 }273}274exports.FrameManager = FrameManager;275class Frame {276 constructor(frameManager, client, parentFrame, frameId) {277 this._url = '';278 this._detached = false;279 this._loaderId = '';280 this._lifecycleEvents = new Set();281 this._frameManager = frameManager;282 this._client = client;283 this._parentFrame = parentFrame;284 this._url = '';285 this._id = frameId;286 this._detached = false;287 this._loaderId = '';288 this._mainWorld = new DOMWorld_1.DOMWorld(frameManager, this, frameManager._timeoutSettings);289 this._secondaryWorld = new DOMWorld_1.DOMWorld(frameManager, this, frameManager._timeoutSettings);290 this._childFrames = new Set();291 if (this._parentFrame)292 this._parentFrame._childFrames.add(this);293 }294 async goto(url, options) {295 return await this._frameManager.navigateFrame(this, url, options);296 }297 async waitForNavigation(options) {298 return await this._frameManager.waitForFrameNavigation(this, options);299 }300 executionContext() {301 return this._mainWorld.executionContext();302 }303 async evaluateHandle(pageFunction, ...args) {304 return this._mainWorld.evaluateHandle(pageFunction, ...args);305 }306 async evaluate(pageFunction, ...args) {307 return this._mainWorld.evaluate(pageFunction, ...args);308 }309 async $(selector) {310 return this._mainWorld.$(selector);311 }312 async $x(expression) {313 return this._mainWorld.$x(expression);314 }315 async $eval(selector, pageFunction, ...args) {316 return this._mainWorld.$eval(selector, pageFunction, ...args);317 }318 async $$eval(selector, pageFunction, ...args) {319 return this._mainWorld.$$eval(selector, pageFunction, ...args);320 }321 async $$(selector) {322 return this._mainWorld.$$(selector);323 }324 async content() {325 return this._secondaryWorld.content();326 }327 async setContent(html, options = {}) {328 return this._secondaryWorld.setContent(html, options);329 }330 name() {331 return this._name || '';332 }333 url() {334 return this._url;335 }336 parentFrame() {337 return this._parentFrame;338 }339 childFrames() {340 return Array.from(this._childFrames);341 }342 isDetached() {343 return this._detached;344 }345 async addScriptTag(options) {346 return this._mainWorld.addScriptTag(options);347 }348 async addStyleTag(options) {349 return this._mainWorld.addStyleTag(options);350 }351 async click(selector, options) {352 return this._secondaryWorld.click(selector, options);353 }354 async focus(selector) {355 return this._secondaryWorld.focus(selector);356 }357 async hover(selector) {358 return this._secondaryWorld.hover(selector);359 }360 select(selector, ...values) {361 return this._secondaryWorld.select(selector, ...values);362 }363 async tap(selector) {364 return this._secondaryWorld.tap(selector);365 }366 async type(selector, text, options) {367 return this._mainWorld.type(selector, text, options);368 }369 waitFor(selectorOrFunctionOrTimeout, options = {}, ...args) {370 const xPathPattern = '//';371 if (helper_1.helper.isString(selectorOrFunctionOrTimeout)) {372 const string = selectorOrFunctionOrTimeout;373 if (string.startsWith(xPathPattern))374 return this.waitForXPath(string, options);375 return this.waitForSelector(string, options);376 }377 if (helper_1.helper.isNumber(selectorOrFunctionOrTimeout))378 return new Promise((fulfill) => setTimeout(fulfill, selectorOrFunctionOrTimeout));379 if (typeof selectorOrFunctionOrTimeout === 'function')380 return this.waitForFunction(selectorOrFunctionOrTimeout, options, ...args);381 return Promise.reject(new Error('Unsupported target type: ' + typeof selectorOrFunctionOrTimeout));382 }383 async waitForSelector(selector, options) {384 const handle = await this._secondaryWorld.waitForSelector(selector, options);385 if (!handle)386 return null;387 const mainExecutionContext = await this._mainWorld.executionContext();388 const result = await mainExecutionContext._adoptElementHandle(handle);389 await handle.dispose();390 return result;391 }392 async waitForXPath(xpath, options) {393 const handle = await this._secondaryWorld.waitForXPath(xpath, options);394 if (!handle)395 return null;396 const mainExecutionContext = await this._mainWorld.executionContext();397 const result = await mainExecutionContext._adoptElementHandle(handle);398 await handle.dispose();399 return result;400 }401 waitForFunction(pageFunction, options = {}, ...args) {402 return this._mainWorld.waitForFunction(pageFunction, options, ...args);403 }404 async title() {405 return this._secondaryWorld.title();406 }407 _navigated(framePayload) {408 this._name = framePayload.name;409 this._url = framePayload.url;410 }411 _navigatedWithinDocument(url) {412 this._url = url;413 }414 _onLifecycleEvent(loaderId, name) {415 if (name === 'init') {416 this._loaderId = loaderId;417 this._lifecycleEvents.clear();418 }419 this._lifecycleEvents.add(name);420 }421 _onLoadingStopped() {422 this._lifecycleEvents.add('DOMContentLoaded');423 this._lifecycleEvents.add('load');424 }425 _detach() {426 this._detached = true;427 this._mainWorld._detach();428 this._secondaryWorld._detach();429 if (this._parentFrame)430 this._parentFrame._childFrames.delete(this);431 this._parentFrame = null;432 }433}434exports.Frame = Frame;435function assertNoLegacyNavigationOptions(options) {...

Full Screen

Full Screen

Frame.js

Source:Frame.js Github

copy

Full Screen

1/* eslint-env node, browser */2const util = require('util')3const { helper } = require('../helper')4const DOMWorld = require('../DOMWorld')5class Frame {6 /**7 *8 * @param {FrameManager} frameManager9 * @param {Object} cdpFrame10 * @param {Frame} [parentFrame]11 * @return {Frame}12 * @since chrome-remote-interface-extra13 */14 static fromCDPFrame (frameManager, cdpFrame, parentFrame) {15 const frame = new Frame(16 frameManager,17 frameManager._client,18 parentFrame,19 cdpFrame.id20 )21 frame._loaderId = cdpFrame.loaderId || ''22 frame._url = cdpFrame.url || ''23 frame._name = cdpFrame.name || ''24 frame._mimeType = cdpFrame.mimeType25 frame._unreachableUrl = cdpFrame.unreachableUrl26 frame._securityOrigin = cdpFrame.securityOrigin27 return frame28 }29 /**30 * @param {!FrameManager} frameManager31 * @param {!Chrome|CRIConnection|CDPSession|Object} client32 * @param {?Frame} parentFrame33 * @param {string} frameId34 */35 constructor (frameManager, client, parentFrame, frameId) {36 /**37 * @type {!FrameManager}38 * @private39 */40 this._frameManager = frameManager41 /**42 * @type {!Chrome|CRIConnection|CDPSession|Object}43 * @private44 */45 this._client = client46 /**47 * @type {?Frame}48 * @private49 */50 this._parentFrame = parentFrame51 /**52 * @type {string}53 */54 this._id = frameId55 /**56 * @type {boolean}57 * @private58 */59 this._detached = false60 /**61 * @type {string}62 * @private63 */64 this._url = ''65 /**66 * @type {string}67 * @private68 */69 this._loaderId = ''70 /**71 * @type {?string}72 */73 this._navigationURL = null74 /**75 * @type {?string}76 */77 this._parentId = parentFrame != null ? parentFrame.id() : null78 /**79 * @type {?string}80 * @since chrome-remote-interface-extra81 */82 this._securityOrigin = null83 /**84 * @type {?string}85 * @since chrome-remote-interface-extra86 */87 this._mimeType = null88 /**89 * @type {?string}90 * @since chrome-remote-interface-extra91 */92 this._unreachableUrl = null93 /**94 * @type {?string}95 * @private96 */97 this._name = null98 /**99 * @type {!Set<string>}100 */101 this._lifecycleEvents = new Set()102 /**103 * @type {DOMWorld}104 */105 this._mainWorld = new DOMWorld(106 frameManager,107 this,108 frameManager._timeoutSettings109 )110 /**111 * @type {DOMWorld}112 */113 this._secondaryWorld = new DOMWorld(114 frameManager,115 this,116 frameManager._timeoutSettings117 )118 /**119 * @type {!Set<Frame>}120 */121 this._childFrames = new Set()122 if (this._parentFrame) this._parentFrame._childFrames.add(this)123 }124 /**125 * @return {!FrameManager}126 */127 frameManager () {128 return this._frameManager129 }130 /**131 * @return {?string}132 * @since chrome-remote-interface-extra133 */134 securityOrigin () {135 return this._securityOrigin136 }137 /**138 * @return {?string}139 * @since chrome-remote-interface-extra140 */141 mimeType () {142 return this._mimeType143 }144 /**145 * @return {?string}146 */147 unreachableUrl () {148 return this._unreachableUrl149 }150 /**151 * @return {string}152 */153 id () {154 return this._id155 }156 /**157 * @return {?string}158 */159 parentFrameId () {160 return this._parentId161 }162 /**163 * @return {string}164 */165 loaderId () {166 return this._loaderId167 }168 /**169 * @return {string}170 */171 name () {172 return this._name || ''173 }174 /**175 * @return {string}176 */177 url () {178 return this._url179 }180 /**181 * @return {?Frame}182 */183 parentFrame () {184 return this._parentFrame185 }186 /**187 * @return {Array<Frame>}188 */189 childFrames () {190 return Array.from(this._childFrames)191 }192 /**193 * @return {boolean}194 */195 isDetached () {196 return this._detached197 }198 /**199 * @param {string} url200 * @param {!{referer?: string, timeout?: number, waitUntil?: string|Array<string>}=} options201 * @return {Promise<Response|undefined>}202 */203 goto (url, options) {204 return this._frameManager.navigateFrame(this, url, options)205 }206 /**207 * @param {!{timeout?: number, waitUntil?: string|Array<string>}} [options]208 * @return {Promise<Response>}209 */210 waitForNavigation (options) {211 return this._frameManager.waitForFrameNavigation(this, options)212 }213 /**214 * @return {?Promise<ExecutionContext>}215 */216 executionContext () {217 return this._mainWorld.executionContext()218 }219 /**220 * @param {Function|string} pageFunction221 * @param {...*} args222 * @return {Promise<JSHandle>}223 */224 evaluateHandle (pageFunction, ...args) {225 return this._mainWorld.evaluateHandle(pageFunction, ...args)226 }227 /**228 * @param {Function|string} pageFunction229 * @param {...*} args230 * @return {Promise<JSHandle>}231 */232 evaluateHandleWithCliAPI (pageFunction, ...args) {233 return this._mainWorld.evaluateHandleWithCliAPI(pageFunction, args, true)234 }235 /**236 * @param {Function|string} pageFunction237 * @param {...*} args238 * @return {Promise<*>}239 */240 evaluate (pageFunction, ...args) {241 return this._mainWorld.evaluate(pageFunction, ...args)242 }243 /**244 * @param {Function|string} pageFunction245 * @param {...*} args246 * @return {Promise<*>}247 */248 evaluateWithCliAPI (pageFunction, ...args) {249 return this._mainWorld.evaluateHandleWithCliAPI(pageFunction, ...args)250 }251 /**252 * Alias for {@link $}253 * @param {string} selector254 * @return {Promise<ElementHandle|undefined>}255 */256 querySelector (selector) {257 return this.$(selector)258 }259 /**260 * Alias for {@link $$}261 * @param {string} selector262 * @return {Promise<Array<ElementHandle>>}263 */264 querySelectorAll (selector) {265 return this.$$(selector)266 }267 /**268 * Alias for {@link $eval}269 * @param {string} selector270 * @param {Function|String} pageFunction271 * @param {...*} args272 * @return {Promise<Object|undefined>}273 */274 querySelectorEval (selector, pageFunction, ...args) {275 return this.$eval(selector, pageFunction, ...args)276 }277 /**278 * Alias for {@link $$eval}279 * @param {string} selector280 * @param {Function|String} pageFunction281 * @param {...*} args282 * @return {Promise<Object|undefined>}283 */284 querySelectorAllEval (selector, pageFunction, ...args) {285 return this.$$eval(selector, pageFunction, ...args)286 }287 /**288 * Alias for {@link $x}289 * @param {string} expression290 * @return {Promise<Array<ElementHandle>>}291 * @since chrome-remote-interface-extra292 */293 xpathQuery (expression) {294 return this.$x(expression)295 }296 /**297 * @param {string} elemId298 * @return {Promise<ElementHandle|undefined>}299 * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById300 * @since chrome-remote-interface-extra301 */302 getElementById (elemId) {303 return this._mainWorld.getElementById(elemId)304 }305 /**306 * @param {string} selector307 * @return {Promise<ElementHandle|undefined>}308 */309 $ (selector) {310 return this._mainWorld.$(selector)311 }312 /**313 * @param {string} expression314 * @return {Promise<Array<ElementHandle>>}315 */316 $x (expression) {317 return this._mainWorld.$x(expression)318 }319 /**320 * @param {string} selector321 * @param {Function|string} pageFunction322 * @param {...*} args323 * @return {Promise<Object|undefined>}324 */325 $eval (selector, pageFunction, ...args) {326 return this._mainWorld.$eval(selector, pageFunction, ...args)327 }328 /**329 * @param {string} selector330 * @param {Function|string} pageFunction331 * @param {...*} args332 * @return {Promise<Object|undefined>}333 */334 $$eval (selector, pageFunction, ...args) {335 return this._mainWorld.$$eval(selector, pageFunction, ...args)336 }337 /**338 * @param {string} selector339 * @return {Promise<Array<ElementHandle>>}340 */341 $$ (selector) {342 return this._mainWorld.$$(selector)343 }344 /**345 * @return {Promise<String>}346 */347 content () {348 return this._secondaryWorld.content()349 }350 /**351 * @param {string} html352 * @param {!{timeout?: number, waitUntil?: string|Array<string>}} [options = {}]353 */354 setContent (html, options = {}) {355 return this._secondaryWorld.setContent(html, options)356 }357 /**358 * @param {!{url?: string, path?: string, content?: string, type?: string}} options359 * @return {Promise<ElementHandle>}360 */361 addScriptTag (options) {362 return this._mainWorld.addScriptTag(options)363 }364 /**365 * @param {!{url?: string, path?: string, content?: string}} options366 * @return {Promise<ElementHandle>}367 */368 addStyleTag (options) {369 return this._mainWorld.addStyleTag(options)370 }371 /**372 * @param {string} selector373 * @param {!{delay?: number, button?: "left"|"right"|"middle", clickCount?: number}=} options374 */375 click (selector, options) {376 return this._secondaryWorld.click(selector, options)377 }378 /**379 * @param {string} selector380 */381 focus (selector) {382 return this._secondaryWorld.focus(selector)383 }384 /**385 * @param {string} selector386 */387 hover (selector) {388 return this._secondaryWorld.hover(selector)389 }390 /**391 * @param {string} selector392 * @param {...string} values393 * @return {Promise<Array<string>>}394 */395 select (selector, ...values) {396 return this._secondaryWorld.select(selector, ...values)397 }398 /**399 * @param {string} selector400 */401 tap (selector) {402 return this._secondaryWorld.tap(selector)403 }404 /**405 * @param {string} selector406 * @param {string} text407 * @param {{delay: (number|undefined)}} [options]408 */409 type (selector, text, options) {410 return this._mainWorld.type(selector, text, options)411 }412 /**413 * @param {(string|number|Function)} selectorOrFunctionOrTimeout414 * @param {?Object} options415 * @param {...*} args416 * @return {Promise<JSHandle|Undefined>}417 */418 waitFor (selectorOrFunctionOrTimeout, options = {}, ...args) {419 const xPathPattern = '//'420 if (helper.isString(selectorOrFunctionOrTimeout)) {421 const string = /** @type {string} */ (selectorOrFunctionOrTimeout)422 if (string.startsWith(xPathPattern)) {423 return this.waitForXPath(string, options)424 }425 return this.waitForSelector(string, options)426 }427 if (helper.isNumber(selectorOrFunctionOrTimeout)) {428 return new Promise(resolve =>429 setTimeout(resolve, /** @type {number} */ (selectorOrFunctionOrTimeout))430 )431 }432 if (typeof selectorOrFunctionOrTimeout === 'function') {433 return this.waitForFunction(selectorOrFunctionOrTimeout, options, ...args)434 }435 return Promise.reject(436 new Error(437 'Unsupported target type: ' + typeof selectorOrFunctionOrTimeout438 )439 )440 }441 /**442 * Returns a ElementHandle for this main frames document object443 * @return {Promise<ElementHandle>}444 */445 document () {446 return this._mainWorld.document()447 }448 /**449 * Returns a JSHandle for this main frames window object450 * @return {Promise<JSHandle>}451 */452 window () {453 return this._mainWorld.window()454 }455 /**456 * @param {Function|string} pageFunction457 * @param {!{polling?: string|number, timeout?: number}} [options = {}]458 * @param {...*} args459 * @return {Promise<JSHandle>}460 */461 waitForFunction (pageFunction, options = {}, ...args) {462 return this._mainWorld.waitForFunction(pageFunction, options, ...args)463 }464 /**465 * @return {Promise<string>}466 */467 title () {468 return this._secondaryWorld.title()469 }470 /**471 * @param {string} selector472 * @param {!{visible?: boolean, hidden?: boolean, timeout?: number}=} options473 * @return {Promise<ElementHandle|undefined>}474 */475 async waitForSelector (selector, options) {476 const handle = await this._secondaryWorld.waitForSelector(selector, options)477 if (!handle) return null478 const mainExecutionContext = await this._mainWorld.executionContext()479 const result = await mainExecutionContext._adoptElementHandle(handle)480 await handle.dispose()481 return result482 }483 /**484 * @param {string} xpath485 * @param {!{visible?: boolean, hidden?: boolean, timeout?: number}} [options]486 * @return {Promise<ElementHandle|undefined>}487 */488 async waitForXPath (xpath, options) {489 const handle = await this._secondaryWorld.waitForXPath(xpath, options)490 if (!handle) return null491 const mainExecutionContext = await this._mainWorld.executionContext()492 const result = await mainExecutionContext._adoptElementHandle(handle)493 await handle.dispose()494 return result495 }496 /**497 * @param {!Object} framePayload498 */499 _navigated (framePayload) {500 this._name = framePayload.name501 this._navigationURL = framePayload.url502 this._url = framePayload.url503 this._mimeType = framePayload.mimeType504 this._unreachableUrl = framePayload.unreachableUrl505 this._securityOrigin = framePayload.securityOrigin506 }507 /**508 * @param {string} url509 */510 _navigatedWithinDocument (url) {511 this._url = url512 }513 /**514 * @param {string} loaderId515 * @param {string} name516 */517 _onLifecycleEvent (loaderId, name) {518 if (name === 'init') {519 this._loaderId = loaderId520 this._lifecycleEvents.clear()521 }522 this._lifecycleEvents.add(name)523 }524 _onLoadingStopped () {525 this._lifecycleEvents.add('DOMContentLoaded')526 this._lifecycleEvents.add('load')527 }528 _detach () {529 this._detached = true530 this._mainWorld._detach()531 this._secondaryWorld._detach()532 if (this._parentFrame) this._parentFrame._childFrames.delete(this)533 this._parentFrame = null534 }535 toJSON () {536 return {537 id: this._id,538 detached: this._detached,539 url: this._url,540 loaderId: this._loaderId,541 parentId: this._parentId,542 securityOrigin: this._securityOrigin,543 mimeType: this._mimeType,544 unreachableUrl: this._unreachableUrl,545 childFrames: this.childFrames()546 }547 }548 /** @ignore */549 // eslint-disable-next-line space-before-function-paren550 [util.inspect.custom](depth, options) {551 if (depth < 0) {552 return options.stylize('[Frame]', 'special')553 }554 const newOptions = Object.assign({}, options, {555 depth: options.depth == null ? null : options.depth - 1556 })557 const inner = util.inspect(558 {559 id: this._id,560 detached: this._detached,561 url: this._url,562 loaderId: this._loaderId,563 parentId: this._parentId,564 securityOrigin: this._securityOrigin,565 mimeType: this._mimeType,566 unreachableUrl: this._unreachableUrl,567 numChildFrames: this._childFrames.size568 },569 newOptions570 )571 return `${options.stylize('Frame', 'special')} ${inner}`572 }573}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await browser.close();7})();8const Nightmare = require('nightmare')9const nightmare = Nightmare({ show: true })10 .screenshot('google.png')11 .end()12 .then(() => {13 console.log('Done!')14 })15 .catch(error => {16 console.error('Search failed:', error)17 })18const { chromium } = require('playwright');19(async () => {20 const browser = await chromium.launch();21 const context = await browser.newContext();22 const page = await context.newPage();23 await page.screenshot({ path: `screenshot.png` });24 await browser.close();25})();26var casper = require('casper').create();27 this.capture('google.png');28});29casper.run();30const {Builder, By, Key, until} = require('selenium-webdriver');31const driver = new Builder().forBrowser('chrome').build();32driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);33driver.wait(until.titleIs('webdriver - Google Search'), 1000);34driver.quit();35exports.config = {36};37describe('angularjs homepage', function() {38 it('should greet the named user', function() {39 element(by.name('q')).sendKeys('webdriver');40 var greeting = element(by.binding('yourName'));41 expect(greeting.getText()).toEqual('Hello Julie!');42 });43});44var wd = require('wd');45var assert = require('assert

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({ path: 'example.png' });6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 await page.screenshot({ path: 'example.png' });13 await browser.close();14})();15const puppeteer = require('puppeteer');16(async () => {17 const browser = await puppeteer.launch();18 const page = await browser.newPage();19 await page.screenshot({ path: 'example.png' });20 await browser.close();21})();22const puppeteer = require('puppeteer');23(async () => {24 const browser = await puppeteer.launch();25 const page = await browser.newPage();26 await page.screenshot({ path: 'example.png' });27 await browser.close();28})();29const puppeteer = require('puppeteer');30(async () => {31 const browser = await puppeteer.launch();32 const page = await browser.newPage();33 await page.screenshot({ path: 'example.png' });34 await browser.close();35})();36const puppeteer = require('puppeteer');37(async () => {38 const browser = await puppeteer.launch();39 const page = await browser.newPage();40 await page.screenshot({ path: 'example.png' });41 await browser.close();42})();43const puppeteer = require('puppeteer');

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({4 });5 const page = await browser.newPage();6 page.on('load', () => console.log('Page loaded!'));7 await page.waitFor(5000);8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: '/home/Downloads'});6 await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: '/home/Downloads'});7 await page.waitForSelector('input[name="q"]');8 await page.type('input[name="q"]', 'puppeteer');9 await page.click('input[type="submit"]');10 await page.waitForNavigation({waitUntil: 'load'});11 await page.waitFor(2000);12 await page.click('a[href="

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 await page.screenshot({path: 'example.png'});13 await browser.close();14})();15const puppeteer = require('puppeteer');16(async () => {17 const browser = await puppeteer.launch();18 const page = await browser.newPage();19 await page.screenshot({path: 'example.png'});20 await browser.close();21})();22const puppeteer = require('puppeteer');23(async () => {24 const browser = await puppeteer.launch();25 const page = await browser.newPage();26 await page.screenshot({path: 'example.png'});27 await browser.close();28})();29const puppeteer = require('puppeteer');30(async () => {31 const browser = await puppeteer.launch();32 const page = await browser.newPage();33 await page.screenshot({path: 'example.png'});34 await browser.close();35})();36const puppeteer = require('puppeteer');37(async () => {38 const browser = await puppeteer.launch();39 const page = await browser.newPage();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Puppeteer automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful