Best JavaScript code snippet using playwright-internal
x-test.js
Source:x-test.js
1/*eslint-env mocha*/2'use strict';3const { assert, refute } = require('@sinonjs/referee');4const logX = require('..');5describe('x', () => {6 it('passes unmatched object through', () => {7 const filter = logX('test');8 const entries = [];9 filter.on('data', (entry) => {10 entries.push(entry);11 });12 const original = { topic: 'ok', data: { key: 'value' } };13 filter.write(original);14 assert.equals(entries.length, 1);15 assert.same(entries[0], original);16 });17 it('passes modified copy with filtered property', () => {18 const filter = logX('key');19 const entries = [];20 filter.on('data', (entry) => {21 entries.push(entry);22 });23 const original_data = { key: 'value' };24 const original_entry = { topic: 'ok', data: original_data };25 filter.write(original_entry);26 assert.equals(entries.length, 1);27 assert.equals(entries[0], { topic: 'ok', data: { key: '·····' } });28 assert.same(entries[0], original_entry);29 refute.same(entries[0].data, original_data);30 });31 it('replaces multiple properties', () => {32 const filter = logX('key1', 'key2');33 const entries = [];34 filter.on('data', (entry) => {35 entries.push(entry);36 });37 const original = { key1: 'value', key2: 'other', key3: 'plain' };38 filter.write({39 topic: 'ok',40 data: original41 });42 assert.equals(entries.length, 1);43 assert.equals(entries[0], {44 topic: 'ok',45 data: {46 key1: '·····',47 key2: '·····',48 key3: 'plain'49 }50 });51 refute.same(entries[0].data, original);52 });53 it('replaces deep property', () => {54 const filter = logX('key.child.deep');55 const entries = [];56 filter.on('data', (entry) => {57 entries.push(entry);58 });59 const original = { key: { child: { deep: 'test' } } };60 filter.write({61 topic: 'ok',62 data: original63 });64 assert.equals(entries.length, 1);65 assert.equals(entries[0], {66 topic: 'ok',67 data: {68 key: {69 child: {70 deep: '·····'71 }72 }73 }74 });75 refute.same(entries[0].data, original.data);76 });77 it('does not fail if deep property does not exist', () => {78 const filter = logX('key.child.deep');79 const entries = [];80 filter.on('data', (entry) => {81 entries.push(entry);82 });83 const original = { topic: 'ok', data: { key: 'is something else' } };84 filter.write(original);85 assert.equals(entries.length, 1);86 assert.same(entries[0], original);87 });88 it('does not add property', () => {89 const filter = logX('key');90 const entries = [];91 filter.on('data', (entry) => {92 entries.push(entry);93 });94 const original = { topic: 'ok', data: {} };95 filter.write(original);96 assert.equals(entries.length, 1);97 assert.same(entries[0], original);98 });99 it('replaces properties in topic', () => {100 const filter = logX({101 wtf: ['key1', 'key2']102 });103 const entries = [];104 filter.on('data', (entry) => {105 entries.push(entry);106 });107 filter.write({ topic: 'wtf', data: { key1: 'a', key2: 'b', key3: 'c' } });108 assert.equals(entries.length, 1);109 assert.equals(entries[0], {110 topic: 'wtf',111 data: {112 key1: '·····',113 key2: '·····',114 key3: 'c'115 }116 });117 });118 it('does not replace property in other topic', () => {119 const filter = logX({120 wtf: ['key']121 });122 const entries = [];123 filter.on('data', (entry) => {124 entries.push(entry);125 });126 const original = { topic: 'input', data: { key: 'value' } };127 filter.write(original);128 assert.equals(entries.length, 1);129 assert.same(entries[0], original);130 });131 it('replaces property in default', () => {132 const filter = logX({133 '*': ['key']134 });135 const entries = [];136 filter.on('data', (entry) => {137 entries.push(entry);138 });139 filter.write({ topic: 'output', data: { key: 'value' } });140 assert.equals(entries.length, 1);141 assert.equals(entries[0], { topic: 'output', data: { key: '·····' } });142 });143 it('replaces index in array', () => {144 const filter = logX('items[0]');145 const entries = [];146 filter.on('data', (entry) => {147 entries.push(entry);148 });149 filter.write({150 topic: 'output',151 data: { items: ['value'] }152 });153 assert.equals(entries.length, 1);154 assert.equals(entries[0], {155 topic: 'output',156 data: { items: ['·····'] }157 });158 });159 it('replaces property in array', () => {160 const filter = logX('items[0].key');161 const entries = [];162 filter.on('data', (entry) => {163 entries.push(entry);164 });165 filter.write({166 topic: 'output',167 data: { items: [{ key: 'value' }] }168 });169 assert.equals(entries.length, 1);170 assert.equals(entries[0], {171 topic: 'output',172 data: { items: [{ key: '·····' }] }173 });174 });175 it('replaces property in reflective property name (single quote)', () => {176 const filter = logX('items[":a"].key');177 const entries = [];178 filter.on('data', (entry) => {179 entries.push(entry);180 });181 filter.write({182 topic: 'output',183 data: { items: { ':a': { key: 'value' } } }184 });185 assert.equals(entries.length, 1);186 assert.equals(entries[0], {187 topic: 'output',188 data: { items: { ':a': { key: '·····' } } }189 });190 });191 it('replaces property in reflective property name (double quote)', () => {192 const filter = logX('items[\':a\'].key');193 const entries = [];194 filter.on('data', (entry) => {195 entries.push(entry);196 });197 filter.write({198 topic: 'output',199 data: { items: { ':a': { key: 'value' } } }200 });201 assert.equals(entries.length, 1);202 assert.equals(entries[0], {203 topic: 'output',204 data: { items: { ':a': { key: '·····' } } }205 });206 });207 it('finds properties in array', () => {208 const filter = logX('items[*].key');209 const entries = [];210 filter.on('data', (entry) => {211 entries.push(entry);212 });213 filter.write({214 topic: 'output',215 data: { items: [{ text: 'visible' }, { key: 'secret' }] }216 });217 assert.equals(entries.length, 1);218 assert.equals(entries[0], {219 topic: 'output',220 data: { items: [{ text: 'visible' }, { key: '·····' }] }221 });222 });223 it('finds properties in object (dot notation)', () => {224 const filter = logX('*.key');225 const entries = [];226 filter.on('data', (entry) => {227 entries.push(entry);228 });229 filter.write({230 topic: 'output',231 data: { foo: { text: 'visible', key: 'secret' }, bar: { key: 'other' } }232 });233 assert.equals(entries.length, 1);234 assert.equals(entries[0], {235 topic: 'output',236 data: { foo: { text: 'visible', key: '·····' }, bar: { key: '·····' } }237 });238 });239 it('finds properties in object (brackets notation)', () => {240 const filter = logX('[*].key');241 const entries = [];242 filter.on('data', (entry) => {243 entries.push(entry);244 });245 filter.write({246 topic: 'output',247 data: { foo: { text: 'visible', key: 'secret' }, bar: { key: 'other' } }248 });249 assert.equals(entries.length, 1);250 assert.equals(entries[0], {251 topic: 'output',252 data: { foo: { text: 'visible', key: '·····' }, bar: { key: '·····' } }253 });254 });255 it('filters all array properties', () => {256 const filter = logX('items[*]');257 const entries = [];258 filter.on('data', (entry) => {259 entries.push(entry);260 });261 filter.write({262 topic: 'output',263 data: { items: ['one', 'two', 'three'] }264 });265 assert.equals(entries.length, 1);266 assert.equals(entries[0], {267 topic: 'output',268 data: { items: ['···', '···', '···'] }269 });270 });271 it('finds properties in object', () => {272 const filter = logX('[*]');273 const entries = [];274 filter.on('data', (entry) => {275 entries.push(entry);276 });277 filter.write({278 topic: 'output',279 data: { a: 'one', b: 'two', c: 'three' }280 });281 assert.equals(entries.length, 1);282 assert.equals(entries[0], {283 topic: 'output',284 data: { a: '···', b: '···', c: '···' }285 });286 });287 it('applies filter for specified namespace', () => {288 const filter = logX.ns('Test', 'key');289 const entries = [];290 filter.on('data', (entry) => {291 entries.push(entry);292 });293 const original_data = { key: 'value' };294 const original_entry = { ns: 'Test', topic: 'disk', data: original_data };295 filter.write(original_entry);296 assert.equals(entries.length, 1);297 assert.equals(entries[0], {298 ns: 'Test',299 topic: 'disk',300 data: { key: '·····' }301 });302 assert.same(entries[0], original_entry);303 refute.same(entries[0].data, original_data);304 });305 it('does not apply filter for different namespace', () => {306 const filter = logX.ns('Test', 'key');307 const entries = [];308 filter.on('data', (entry) => {309 entries.push(entry);310 });311 const original_data = { key: 'value' };312 const original_entry = { ns: 'Foo', topic: 'disk', data: original_data };313 filter.write(original_entry);314 assert.equals(entries.length, 1);315 assert.same(entries[0], original_entry);316 assert.same(entries[0].data, original_data);317 });318 it('combines multiple streams', () => {319 const all = logX.all(320 logX('a'),321 logX('b'),322 logX('c')323 );324 const entries = [];325 all.on('data', (entry) => {326 entries.push(entry);327 });328 all.write({ topic: 'disk', data: { a: 'A' } });329 all.write({ topic: 'disk', data: { b: 'B' } });330 all.write({ topic: 'disk', data: { c: 'C' } });331 all.write({ topic: 'disk', data: { a: 'A', b: 'B' } });332 all.write({ topic: 'disk', data: { b: 'B', c: 'C' } });333 all.write({ topic: 'disk', data: { a: 'A', c: 'C' } });334 assert.equals(entries.length, 6);335 assert.match(entries[0], { data: { a: '·····' } });336 assert.match(entries[1], { data: { b: '·····' } });337 assert.match(entries[2], { data: { c: '·····' } });338 assert.match(entries[3], { data: { a: '·····', b: '·····' } });339 assert.match(entries[4], { data: { b: '·····', c: '·····' } });340 assert.match(entries[5], { data: { a: '·····', c: '·····' } });341 });342 it('combines deep filters', () => {343 const all = logX.all(344 logX('a.x'),345 logX('b')346 );347 const entries = [];348 all.on('data', (entry) => {349 entries.push(entry);350 });351 all.write({ topic: 'disk', data: { a: { x: 'A' } } });352 all.write({ topic: 'disk', data: { b: 'B' } });353 all.write({ topic: 'disk', data: { a: { x: 'A' }, b: 'B' } });354 assert.equals(entries.length, 3);355 assert.match(entries[0], { data: { a: { x: '·····' } } });356 assert.match(entries[1], { data: { b: '·····' } });357 assert.match(entries[2], { data: { a: { x: '·····' }, b: '·····' } });358 });359 describe('with null property', () => {360 it('does not fail if property is null', () => {361 const filter = logX('key.child');362 refute.exception(() => {363 filter.write({ topic: 'ok', data: { key: null } });364 });365 });366 it('does not fail if deep property is null', () => {367 const filter = logX('key.child.deep');368 refute.exception(() => {369 filter.write({ topic: 'ok', data: { key: null } });370 });371 });372 });373 describe('with prototype-less object', () => {374 it('does not fail on prototype-less object', () => {375 const filter = logX('key');376 refute.exception(() => {377 filter.write({ topic: 'ok', data: Object.create(null) });378 });379 });380 it('does not fail on prototype-less object (key.child)', () => {381 const filter = logX('key.child');382 refute.exception(() => {383 filter.write({ topic: 'ok', data: Object.create(null) });384 });385 });386 it('does not fail on prototype-less object ([*])', () => {387 const filter = logX('[*]');388 const data = Object.create(null);389 data.key = 1;390 refute.exception(() => {391 filter.write({ topic: 'ok', data });392 });393 });394 it('does not fail on prototype-less object (*.key)', () => {395 const filter = logX('*.key');396 const data = Object.create(null);397 data.key = 1;398 refute.exception(() => {399 filter.write({ topic: 'ok', data });400 });401 });402 });...
cache-base-debug.js
Source:cache-base-debug.js
1/*2YUI 3.17.2 (build 9c3c78e)3Copyright 2014 Yahoo! Inc. All rights reserved.4Licensed under the BSD License.5http://yuilibrary.com/license/6*/7YUI.add('cache-base', function (Y, NAME) {8/**9 * The Cache utility provides a common configurable interface for components to10 * cache and retrieve data from a local JavaScript struct.11 *12 * @module cache13 * @main14 */15/**16 * Provides the base class for the YUI Cache utility.17 *18 * @submodule cache-base19 */20var LANG = Y.Lang,21 isDate = Y.Lang.isDate,22/**23 * Base class for the YUI Cache utility.24 * @class Cache25 * @extends Base26 * @constructor27 */28Cache = function() {29 Cache.superclass.constructor.apply(this, arguments);30};31 /////////////////////////////////////////////////////////////////////////////32 //33 // Cache static properties34 //35 /////////////////////////////////////////////////////////////////////////////36Y.mix(Cache, {37 /**38 * Class name.39 *40 * @property NAME41 * @type String42 * @static43 * @final44 * @value "cache"45 */46 NAME: "cache",47 ATTRS: {48 /////////////////////////////////////////////////////////////////////////////49 //50 // Cache Attributes51 //52 /////////////////////////////////////////////////////////////////////////////53 /**54 * @attribute max55 * @description Maximum number of entries the Cache can hold.56 * Set to 0 to turn off caching.57 * @type Number58 * @default 059 */60 max: {61 value: 0,62 setter: "_setMax"63 },64 /**65 * @attribute size66 * @description Number of entries currently cached.67 * @type Number68 */69 size: {70 readOnly: true,71 getter: "_getSize"72 },73 /**74 * @attribute uniqueKeys75 * @description Validate uniqueness of stored keys. Default is false and76 * is more performant.77 * @type Boolean78 */79 uniqueKeys: {80 value: false81 },82 /**83 * @attribute expires84 * @description Absolute Date when data expires or85 * relative number of milliseconds. Zero disables expiration.86 * @type Date | Number87 * @default 088 */89 expires: {90 value: 0,91 validator: function(v) {92 return Y.Lang.isDate(v) || (Y.Lang.isNumber(v) && v >= 0);93 }94 },95 /**96 * @attribute entries97 * @description Cached entries.98 * @type Array99 */100 entries: {101 readOnly: true,102 getter: "_getEntries"103 }104 }105});106Y.extend(Cache, Y.Base, {107 /////////////////////////////////////////////////////////////////////////////108 //109 // Cache private properties110 //111 /////////////////////////////////////////////////////////////////////////////112 /**113 * Array of request/response objects indexed chronologically.114 *115 * @property _entries116 * @type Object[]117 * @private118 */119 _entries: null,120 /////////////////////////////////////////////////////////////////////////////121 //122 // Cache private methods123 //124 /////////////////////////////////////////////////////////////////////////////125 /**126 * @method initializer127 * @description Internal init() handler.128 * @param config {Object} Config object.129 * @private130 */131 initializer: function(config) {132 /**133 * @event add134 * @description Fired when an entry is added.135 * @param e {EventFacade} Event Facade with the following properties:136 * <dl>137 * <dt>entry (Object)</dt> <dd>The cached entry.</dd>138 * </dl>139 * @preventable _defAddFn140 */141 this.publish("add", {defaultFn: this._defAddFn});142 /**143 * @event flush144 * @description Fired when the cache is flushed.145 * @param e {EventFacade} Event Facade object.146 * @preventable _defFlushFn147 */148 this.publish("flush", {defaultFn: this._defFlushFn});149 /**150 * @event request151 * @description Fired when an entry is requested from the cache.152 * @param e {EventFacade} Event Facade with the following properties:153 * <dl>154 * <dt>request (Object)</dt> <dd>The request object.</dd>155 * </dl>156 */157 /**158 * @event retrieve159 * @description Fired when an entry is retrieved from the cache.160 * @param e {EventFacade} Event Facade with the following properties:161 * <dl>162 * <dt>entry (Object)</dt> <dd>The retrieved entry.</dd>163 * </dl>164 */165 // Initialize internal values166 this._entries = [];167 Y.log("Cache initialized", "info", "cache");168 },169 /**170 * @method destructor171 * @description Internal destroy() handler.172 * @private173 */174 destructor: function() {175 this._entries = [];176 Y.log("Cache destroyed", "info", "cache");177 },178 /////////////////////////////////////////////////////////////////////////////179 //180 // Cache protected methods181 //182 /////////////////////////////////////////////////////////////////////////////183 /**184 * Sets max.185 *186 * @method _setMax187 * @protected188 */189 _setMax: function(value) {190 // If the cache is full, make room by removing stalest element (index=0)191 var entries = this._entries;192 if(value > 0) {193 if(entries) {194 while(entries.length > value) {195 entries.shift();196 }197 }198 }199 else {200 value = 0;201 this._entries = [];202 }203 return value;204 },205 /**206 * Gets size.207 *208 * @method _getSize209 * @protected210 */211 _getSize: function() {212 return this._entries.length;213 },214 /**215 * Gets all entries.216 *217 * @method _getEntries218 * @protected219 */220 _getEntries: function() {221 return this._entries;222 },223 /**224 * Adds entry to cache.225 *226 * @method _defAddFn227 * @param e {EventFacade} Event Facade with the following properties:228 * <dl>229 * <dt>entry (Object)</dt> <dd>The cached entry.</dd>230 * </dl>231 * @protected232 */233 _defAddFn: function(e) {234 var entries = this._entries,235 entry = e.entry,236 max = this.get("max"),237 pos;238 // If uniqueKeys is true and item exists with this key, then remove it.239 if (this.get("uniqueKeys")) {240 pos = this._position(e.entry.request);241 if (LANG.isValue(pos)) {242 entries.splice(pos, 1);243 }244 }245 // If the cache at or over capacity, make room by removing stalest246 // element(s) starting at index-0.247 while (max && entries.length >= max) {248 entries.shift();249 }250 // Add entry to cache in the newest position, at the end of the array251 entries[entries.length] = entry;252 Y.log("Cached entry: " + Y.dump(entry), "info", "cache");253 },254 /**255 * Flushes cache.256 *257 * @method _defFlushFn258 * @param e {EventFacade} Event Facade object.259 * @protected260 */261 _defFlushFn: function(e) {262 var entries = this._entries,263 details = e.details[0],264 pos;265 //passed an item, flush only that266 if(details && LANG.isValue(details.request)) {267 pos = this._position(details.request);268 if(LANG.isValue(pos)) {269 entries.splice(pos,1);270 Y.log("Flushed cache item " + Y.dump(details.request), "info", "cache");271 }272 }273 //no item, flush everything274 else {275 this._entries = [];276 Y.log("Cache flushed", "info", "cache");277 }278 },279 /**280 * Default overridable method compares current request with given cache entry.281 * Returns true if current request matches the cached request, otherwise282 * false. Implementers should override this method to customize the283 * cache-matching algorithm.284 *285 * @method _isMatch286 * @param request {Object} Request object.287 * @param entry {Object} Cached entry.288 * @return {Boolean} True if current request matches given cached request, false otherwise.289 * @protected290 */291 _isMatch: function(request, entry) {292 if(!entry.expires || new Date() < entry.expires) {293 return (request === entry.request);294 }295 return false;296 },297 /**298 * Returns position of a request in the entries array, otherwise null.299 *300 * @method _position301 * @param request {Object} Request object.302 * @return {Number} Array position if found, null otherwise.303 * @protected304 */305 _position: function(request) {306 // If cache is enabled...307 var entries = this._entries,308 length = entries.length,309 i = length-1;310 if((this.get("max") === null) || this.get("max") > 0) {311 // Loop through each cached entry starting from the newest312 for(; i >= 0; i--) {313 // Execute matching function314 if(this._isMatch(request, entries[i])) {315 return i;316 }317 }318 }319 return null;320 },321 /////////////////////////////////////////////////////////////////////////////322 //323 // Cache public methods324 //325 /////////////////////////////////////////////////////////////////////////////326 /**327 * Adds a new entry to the cache of the format328 * {request:request, response:response, cached:cached, expires:expires}.329 * If cache is full, evicts the stalest entry before adding the new one.330 *331 * @method add332 * @param request {Object} Request value.333 * @param response {Object} Response value.334 */335 add: function(request, response) {336 var expires = this.get("expires");337 if(this.get("initialized") && ((this.get("max") === null) || this.get("max") > 0) &&338 (LANG.isValue(request) || LANG.isNull(request) || LANG.isUndefined(request))) {339 this.fire("add", {entry: {340 request:request,341 response:response,342 cached: new Date(),343 expires: isDate(expires) ? expires :344 (expires ? new Date(new Date().getTime() + this.get("expires")) : null)345 }});346 }347 else {348 Y.log("Could not add " + Y.dump(response) + " to cache for " + Y.dump(request), "info", "cache");349 }350 },351 /**352 * Flushes cache.353 *354 * @method flush355 */356 flush: function(request) {357 this.fire("flush", { request: (LANG.isValue(request) ? request : null) });358 },359 /**360 * Retrieves cached object for given request, if available, and refreshes361 * entry in the cache. Returns null if there is no cache match.362 *363 * @method retrieve364 * @param request {Object} Request object.365 * @return {Object} Cached object with the properties request and response, or null.366 */367 retrieve: function(request) {368 // If cache is enabled...369 var entries = this._entries,370 length = entries.length,371 entry = null,372 pos;373 if((length > 0) && ((this.get("max") === null) || (this.get("max") > 0))) {374 this.fire("request", {request: request});375 pos = this._position(request);376 if(LANG.isValue(pos)) {377 entry = entries[pos];378 this.fire("retrieve", {entry: entry});379 // Refresh the position of the cache hit380 if(pos < length-1) {381 // Remove element from its original location382 entries.splice(pos,1);383 // Add as newest384 entries[entries.length] = entry;385 Y.log("Refreshed cache entry: " + Y.dump(entry) +386 " for request: " + Y.dump(request), "info", "cache");387 }388 Y.log("Retrieved cached response: " + Y.dump(entry) +389 " for request: " + Y.dump(request), "info", "cache");390 return entry;391 }392 }393 return null;394 }395});396Y.Cache = Cache;...
cache-base.js
Source:cache-base.js
1/*2YUI 3.17.2 (build 9c3c78e)3Copyright 2014 Yahoo! Inc. All rights reserved.4Licensed under the BSD License.5http://yuilibrary.com/license/6*/7YUI.add('cache-base', function (Y, NAME) {8/**9 * The Cache utility provides a common configurable interface for components to10 * cache and retrieve data from a local JavaScript struct.11 *12 * @module cache13 * @main14 */15/**16 * Provides the base class for the YUI Cache utility.17 *18 * @submodule cache-base19 */20var LANG = Y.Lang,21 isDate = Y.Lang.isDate,22/**23 * Base class for the YUI Cache utility.24 * @class Cache25 * @extends Base26 * @constructor27 */28Cache = function() {29 Cache.superclass.constructor.apply(this, arguments);30};31 /////////////////////////////////////////////////////////////////////////////32 //33 // Cache static properties34 //35 /////////////////////////////////////////////////////////////////////////////36Y.mix(Cache, {37 /**38 * Class name.39 *40 * @property NAME41 * @type String42 * @static43 * @final44 * @value "cache"45 */46 NAME: "cache",47 ATTRS: {48 /////////////////////////////////////////////////////////////////////////////49 //50 // Cache Attributes51 //52 /////////////////////////////////////////////////////////////////////////////53 /**54 * @attribute max55 * @description Maximum number of entries the Cache can hold.56 * Set to 0 to turn off caching.57 * @type Number58 * @default 059 */60 max: {61 value: 0,62 setter: "_setMax"63 },64 /**65 * @attribute size66 * @description Number of entries currently cached.67 * @type Number68 */69 size: {70 readOnly: true,71 getter: "_getSize"72 },73 /**74 * @attribute uniqueKeys75 * @description Validate uniqueness of stored keys. Default is false and76 * is more performant.77 * @type Boolean78 */79 uniqueKeys: {80 value: false81 },82 /**83 * @attribute expires84 * @description Absolute Date when data expires or85 * relative number of milliseconds. Zero disables expiration.86 * @type Date | Number87 * @default 088 */89 expires: {90 value: 0,91 validator: function(v) {92 return Y.Lang.isDate(v) || (Y.Lang.isNumber(v) && v >= 0);93 }94 },95 /**96 * @attribute entries97 * @description Cached entries.98 * @type Array99 */100 entries: {101 readOnly: true,102 getter: "_getEntries"103 }104 }105});106Y.extend(Cache, Y.Base, {107 /////////////////////////////////////////////////////////////////////////////108 //109 // Cache private properties110 //111 /////////////////////////////////////////////////////////////////////////////112 /**113 * Array of request/response objects indexed chronologically.114 *115 * @property _entries116 * @type Object[]117 * @private118 */119 _entries: null,120 /////////////////////////////////////////////////////////////////////////////121 //122 // Cache private methods123 //124 /////////////////////////////////////////////////////////////////////////////125 /**126 * @method initializer127 * @description Internal init() handler.128 * @param config {Object} Config object.129 * @private130 */131 initializer: function(config) {132 /**133 * @event add134 * @description Fired when an entry is added.135 * @param e {EventFacade} Event Facade with the following properties:136 * <dl>137 * <dt>entry (Object)</dt> <dd>The cached entry.</dd>138 * </dl>139 * @preventable _defAddFn140 */141 this.publish("add", {defaultFn: this._defAddFn});142 /**143 * @event flush144 * @description Fired when the cache is flushed.145 * @param e {EventFacade} Event Facade object.146 * @preventable _defFlushFn147 */148 this.publish("flush", {defaultFn: this._defFlushFn});149 /**150 * @event request151 * @description Fired when an entry is requested from the cache.152 * @param e {EventFacade} Event Facade with the following properties:153 * <dl>154 * <dt>request (Object)</dt> <dd>The request object.</dd>155 * </dl>156 */157 /**158 * @event retrieve159 * @description Fired when an entry is retrieved from the cache.160 * @param e {EventFacade} Event Facade with the following properties:161 * <dl>162 * <dt>entry (Object)</dt> <dd>The retrieved entry.</dd>163 * </dl>164 */165 // Initialize internal values166 this._entries = [];167 },168 /**169 * @method destructor170 * @description Internal destroy() handler.171 * @private172 */173 destructor: function() {174 this._entries = [];175 },176 /////////////////////////////////////////////////////////////////////////////177 //178 // Cache protected methods179 //180 /////////////////////////////////////////////////////////////////////////////181 /**182 * Sets max.183 *184 * @method _setMax185 * @protected186 */187 _setMax: function(value) {188 // If the cache is full, make room by removing stalest element (index=0)189 var entries = this._entries;190 if(value > 0) {191 if(entries) {192 while(entries.length > value) {193 entries.shift();194 }195 }196 }197 else {198 value = 0;199 this._entries = [];200 }201 return value;202 },203 /**204 * Gets size.205 *206 * @method _getSize207 * @protected208 */209 _getSize: function() {210 return this._entries.length;211 },212 /**213 * Gets all entries.214 *215 * @method _getEntries216 * @protected217 */218 _getEntries: function() {219 return this._entries;220 },221 /**222 * Adds entry to cache.223 *224 * @method _defAddFn225 * @param e {EventFacade} Event Facade with the following properties:226 * <dl>227 * <dt>entry (Object)</dt> <dd>The cached entry.</dd>228 * </dl>229 * @protected230 */231 _defAddFn: function(e) {232 var entries = this._entries,233 entry = e.entry,234 max = this.get("max"),235 pos;236 // If uniqueKeys is true and item exists with this key, then remove it.237 if (this.get("uniqueKeys")) {238 pos = this._position(e.entry.request);239 if (LANG.isValue(pos)) {240 entries.splice(pos, 1);241 }242 }243 // If the cache at or over capacity, make room by removing stalest244 // element(s) starting at index-0.245 while (max && entries.length >= max) {246 entries.shift();247 }248 // Add entry to cache in the newest position, at the end of the array249 entries[entries.length] = entry;250 },251 /**252 * Flushes cache.253 *254 * @method _defFlushFn255 * @param e {EventFacade} Event Facade object.256 * @protected257 */258 _defFlushFn: function(e) {259 var entries = this._entries,260 details = e.details[0],261 pos;262 //passed an item, flush only that263 if(details && LANG.isValue(details.request)) {264 pos = this._position(details.request);265 if(LANG.isValue(pos)) {266 entries.splice(pos,1);267 }268 }269 //no item, flush everything270 else {271 this._entries = [];272 }273 },274 /**275 * Default overridable method compares current request with given cache entry.276 * Returns true if current request matches the cached request, otherwise277 * false. Implementers should override this method to customize the278 * cache-matching algorithm.279 *280 * @method _isMatch281 * @param request {Object} Request object.282 * @param entry {Object} Cached entry.283 * @return {Boolean} True if current request matches given cached request, false otherwise.284 * @protected285 */286 _isMatch: function(request, entry) {287 if(!entry.expires || new Date() < entry.expires) {288 return (request === entry.request);289 }290 return false;291 },292 /**293 * Returns position of a request in the entries array, otherwise null.294 *295 * @method _position296 * @param request {Object} Request object.297 * @return {Number} Array position if found, null otherwise.298 * @protected299 */300 _position: function(request) {301 // If cache is enabled...302 var entries = this._entries,303 length = entries.length,304 i = length-1;305 if((this.get("max") === null) || this.get("max") > 0) {306 // Loop through each cached entry starting from the newest307 for(; i >= 0; i--) {308 // Execute matching function309 if(this._isMatch(request, entries[i])) {310 return i;311 }312 }313 }314 return null;315 },316 /////////////////////////////////////////////////////////////////////////////317 //318 // Cache public methods319 //320 /////////////////////////////////////////////////////////////////////////////321 /**322 * Adds a new entry to the cache of the format323 * {request:request, response:response, cached:cached, expires:expires}.324 * If cache is full, evicts the stalest entry before adding the new one.325 *326 * @method add327 * @param request {Object} Request value.328 * @param response {Object} Response value.329 */330 add: function(request, response) {331 var expires = this.get("expires");332 if(this.get("initialized") && ((this.get("max") === null) || this.get("max") > 0) &&333 (LANG.isValue(request) || LANG.isNull(request) || LANG.isUndefined(request))) {334 this.fire("add", {entry: {335 request:request,336 response:response,337 cached: new Date(),338 expires: isDate(expires) ? expires :339 (expires ? new Date(new Date().getTime() + this.get("expires")) : null)340 }});341 }342 else {343 }344 },345 /**346 * Flushes cache.347 *348 * @method flush349 */350 flush: function(request) {351 this.fire("flush", { request: (LANG.isValue(request) ? request : null) });352 },353 /**354 * Retrieves cached object for given request, if available, and refreshes355 * entry in the cache. Returns null if there is no cache match.356 *357 * @method retrieve358 * @param request {Object} Request object.359 * @return {Object} Cached object with the properties request and response, or null.360 */361 retrieve: function(request) {362 // If cache is enabled...363 var entries = this._entries,364 length = entries.length,365 entry = null,366 pos;367 if((length > 0) && ((this.get("max") === null) || (this.get("max") > 0))) {368 this.fire("request", {request: request});369 pos = this._position(request);370 if(LANG.isValue(pos)) {371 entry = entries[pos];372 this.fire("retrieve", {entry: entry});373 // Refresh the position of the cache hit374 if(pos < length-1) {375 // Remove element from its original location376 entries.splice(pos,1);377 // Add as newest378 entries[entries.length] = entry;379 }380 return entry;381 }382 }383 return null;384 }385});386Y.Cache = Cache;...
background.js
Source:background.js
1// Copyright 2014 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4'use strict';5/**6 * @param {Object.<string, string>} stringData String data.7 * @param {VolumeManager} volumeManager Volume manager.8 */9function BackgroundComponents(stringData, volumeManager) {10 /**11 * String data.12 * @type {Object.<string, string>}13 */14 this.stringData = stringData;15 /**16 * Volume manager.17 * @type {VolumeManager}18 */19 this.volumeManager = volumeManager;20 Object.freeze(this);21}22/**23 * Loads background component.24 * @return {Promise} Promise fulfilled with BackgroundComponents.25 */26BackgroundComponents.load = function() {27 var stringDataPromise = new Promise(function(fulfill) {28 chrome.fileBrowserPrivate.getStrings(function(stringData) {29 loadTimeData.data = stringData;30 fulfill(stringData);31 });32 });33 // VolumeManager should be obtained after stringData initialized.34 var volumeManagerPromise = stringDataPromise.then(function() {35 return new Promise(function(fulfill) {36 VolumeManager.getInstance(fulfill);37 });38 });39 return Promise.all([stringDataPromise, volumeManagerPromise]).then(40 function(args) {41 return new BackgroundComponents(args[0], args[1]);42 });43};44/**45 * Promise to be fulfilled with singleton instance of background components.46 * @type {Promise}47 */48var backgroundComponentsPromise = BackgroundComponents.load();49/**50 * Resolves file system names and obtains entries.51 * @param {Array.<FileEntry>} entries Names of isolated file system.52 * @return {Promise} Promise to be fulfilled with an entry array.53 */54function resolveEntries(entries) {55 return new Promise(function(fulfill, reject) {56 chrome.fileBrowserPrivate.resolveIsolatedEntries(entries,57 function(externalEntries) {58 if (!chrome.runtime.lastError)59 fulfill(externalEntries);60 else61 reject(chrome.runtime.lastError);62 });63 });64}65/**66 * Obtains child entries.67 * @param {DirectoryEntry} entry Directory entry.68 * @return {Promise} Promise to be fulfilled with child entries.69 */70function getChildren(entry) {71 var reader = entry.createReader();72 var readEntries = function() {73 return new Promise(reader.readEntries.bind(reader)).then(function(entries) {74 if (entries.length === 0)75 return [];76 return readEntries().then(function(nextEntries) {77 return entries.concat(nextEntries);78 });79 });80 };81 return readEntries().then(function(entries) {82 return entries.sort(function(a, b) {83 return a.name.localeCompare(b.name);84 });85 });86}87/**88 * Promise to be fulfilled with single application window.89 * @type {Promise}90 */91var appWindowPromise = Promise.resolve(null);92/**93 * Promise to be fulfilled with the current window is closed.94 * @type {Promise}95 */96var closingPromise = Promise.resolve(null);97/**98 * Launches the application with entries.99 *100 * @param {Promise} selectedEntriesPromise Promise to be fulfilled with the101 * entries that are stored in the exteranl file system (not in the isolated102 * file system).103 */104function launch(selectedEntriesPromise) {105 // If there is the previous window, close the window.106 appWindowPromise = appWindowPromise.then(function(appWindow) {107 if (appWindow) {108 appWindow.close();109 return closingPromise;110 }111 });112 // Create a new window.113 appWindowPromise = appWindowPromise.then(function() {114 return new Promise(function(fulfill) {115 chrome.app.window.create(116 'gallery.html',117 {118 id: 'gallery',119 innerBounds: {120 minWidth: 800,121 minHeight: 300122 },123 frame: 'none'124 },125 function(appWindow) {126 appWindow.contentWindow.addEventListener(127 'load', fulfill.bind(null, appWindow));128 closingPromise = new Promise(function(fulfill) {129 appWindow.onClosed.addListener(fulfill);130 });131 });132 });133 });134 // Initialize the window document.135 appWindowPromise = Promise.all([136 appWindowPromise,137 backgroundComponentsPromise,138 ]).then(function(args) {139 args[0].contentWindow.initialize(args[1]);140 return args[0];141 });142 // If only 1 entry is selected, retrieve entries in the same directory.143 // Otherwise, just use the selectedEntries as an entry set.144 var allEntriesPromise = selectedEntriesPromise.then(function(entries) {145 if (entries.length === 1) {146 var parentPromise = new Promise(entries[0].getParent.bind(entries[0]));147 return parentPromise.then(getChildren).then(function(entries) {148 return entries.filter(FileType.isImage);149 });150 } else {151 return entries;152 }153 });154 // Open entries.155 return Promise.all([156 appWindowPromise,157 allEntriesPromise,158 selectedEntriesPromise159 ]).then(function(args) {160 args[0].contentWindow.loadEntries(args[1], args[2]);161 });162}163chrome.app.runtime.onLaunched.addListener(function(launchData) {164 // Skip if files are not selected.165 if (!launchData || !launchData.items || launchData.items.length === 0)166 return;167 // Obtains entries in non-isolated file systems.168 // The entries in launchData are stored in the isolated file system.169 // We need to map the isolated entries to the normal entries to retrieve their170 // parent directory.171 var isolatedEntries = launchData.items.map(function(item) {172 return item.entry;173 });174 var selectedEntriesPromise = backgroundComponentsPromise.then(function() {175 return resolveEntries(isolatedEntries);176 });177 launch(selectedEntriesPromise).catch(function(error) {178 console.error(error.stack || error);179 });180});181// If is is run in the browser test, wait for the test resources are installed182// as a component extension, and then load the test resources.183if (chrome.test) {184 chrome.runtime.onMessageExternal.addListener(function(message) {185 if (message.name !== 'testResourceLoaded')186 return;187 var script = document.createElement('script');188 script.src =189 'chrome-extension://ejhcmmdhhpdhhgmifplfmjobgegbibkn' +190 '/gallery/test_loader.js';191 document.documentElement.appendChild(script);192 });...
performance.js
Source:performance.js
1/*---------------------------------------------------------------------------------------------2 * Copyright (c) Microsoft Corporation. All rights reserved.3 * Licensed under the MIT License. See License.txt in the project root for license information.4 *--------------------------------------------------------------------------------------------*/5'use strict';6/*global define*/7// This module can be loaded in an amd and commonjs-context.8// Because we want both instances to use the same perf-data9// we store them globally10// stores data as 'type','name','startTime','duration'11global._performanceEntries = global._performanceEntries || [];12if (typeof define !== "function" && typeof module === "object" && typeof module.exports === "object") {13 // this is commonjs, fake amd14 global.define = function (dep, callback) {15 module.exports = callback();16 global.define = undefined;17 };18}19define([], function () {20 // const _now = global.performance && performance.now ? performance.now : Date.now21 const _now = Date.now;22 function importEntries(entries) {23 global._performanceEntries.splice(0, 0, ...entries);24 }25 function exportEntries() {26 return global._performanceEntries.slice(0);27 }28 function getEntries(type, name) {29 const result = [];30 const entries = global._performanceEntries;31 for (let i = 0; i < entries.length; i += 4) {32 if (entries[i] === type && (name === void 0 || entries[i + 1] === name)) {33 result.push({34 type: entries[i],35 name: entries[i + 1],36 startTime: entries[i + 2],37 duration: entries[i + 3],38 });39 }40 }41 return result.sort((a, b) => {42 return a.startTime - b.startTime;43 });44 }45 function getEntry(type, name) {46 const entries = global._performanceEntries;47 for (let i = 0; i < entries.length; i += 4) {48 if (entries[i] === type && entries[i + 1] === name) {49 return {50 type: entries[i],51 name: entries[i + 1],52 startTime: entries[i + 2],53 duration: entries[i + 3],54 };55 }56 }57 }58 function getDuration(from, to) {59 const entries = global._performanceEntries;60 let name = from;61 let startTime = 0;62 for (let i = 0; i < entries.length; i += 4) {63 if (entries[i + 1] === name) {64 if (name === from) {65 // found `from` (start of interval)66 name = to;67 startTime = entries[i + 2];68 } else {69 // from `to` (end of interval)70 return entries[i + 2] - startTime;71 }72 }73 }74 return 0;75 }76 function mark(name) {77 global._performanceEntries.push('mark', name, _now(), 0);78 if (typeof console.timeStamp === 'function') {79 console.timeStamp(name);80 }81 }82 function time(name) {83 let from = `${name}/start`;84 mark(from);85 return { stop() { measure(name, from); } };86 }87 function measure(name, from, to) {88 let startTime;89 let duration;90 let now = _now();91 if (!from) {92 startTime = now;93 } else {94 startTime = _getLastStartTime(from);95 }96 if (!to) {97 duration = now - startTime;98 } else {99 duration = _getLastStartTime(to) - startTime;100 }101 global._performanceEntries.push('measure', name, startTime, duration);102 }103 function _getLastStartTime(name) {104 const entries = global._performanceEntries;105 for (let i = entries.length - 1; i >= 0; i -= 4) {106 if (entries[i - 2] === name) {107 return entries[i - 1];108 }109 }110 throw new Error(name + ' not found');111 }112 var exports = {113 mark: mark,114 measure: measure,115 time: time,116 getEntries: getEntries,117 getEntry: getEntry,118 getDuration: getDuration,119 importEntries: importEntries,120 exportEntries: exportEntries121 };122 return exports;...
entries.js
Source:entries.js
...5if ("entries" in Object) {6 assertEq(Object.entries.length, 1);7 var o, entries;8 o = { a: 3, b: 2 };9 entries = Object.entries(o);10 assertDeepEq(entries, [["a", 3], ["b", 2]]);11 o = { get a() { return 17; }, b: 2 };12 entries = Object.entries(o),13 assertDeepEq(entries, [["a", 17], ["b", 2]]);14 o = { __iterator__: function() { throw new Error("non-standard __iterator__ called?"); } };15 entries = Object.entries(o);16 assertDeepEq(entries, [["__iterator__", o.__iterator__]]);17 o = { a: 1, b: 2 };18 delete o.a;19 o.a = 3;20 entries = Object.entries(o);21 assertDeepEq(entries, [["b", 2], ["a", 3]]);22 o = [0, 1, 2];23 entries = Object.entries(o);24 assertDeepEq(entries, [["0", 0], ["1", 1], ["2", 2]]);25 o = /./.exec("abc");26 entries = Object.entries(o);27 assertDeepEq(entries, [["0", "a"], ["index", 0], ["input", "abc"]]);28 o = { a: 1, b: 2, c: 3 };29 delete o.b;30 o.b = 5;31 entries = Object.entries(o);32 assertDeepEq(entries, [["a", 1], ["c", 3], ["b", 5]]);33 function f() { }34 f.prototype.p = 1;35 o = new f();36 o.g = 1;37 entries = Object.entries(o);38 assertDeepEq(entries, [["g", 1]]);39 var o = {get a() {delete this.b; return 1}, b: 2, c: 3};40 entries = Object.entries(o);41 assertDeepEq(entries, [["a", 1], ["c", 3]]);42 assertThrowsInstanceOf(() => Object.entries(), TypeError);43 assertThrowsInstanceOf(() => Object.entries(undefined), TypeError);44 assertThrowsInstanceOf(() => Object.entries(null), TypeError);45 assertDeepEq(Object.entries(1), []);46 assertDeepEq(Object.entries(true), []);47 if (typeof Symbol === "function")48 assertDeepEq(Object.entries(Symbol("foo")), []);49 assertDeepEq(Object.entries("foo"), [["0", "f"], ["1", "o"], ["2", "o"]]);50 entries = Object.entries({51 get a(){52 Object.defineProperty(this, "b", {enumerable: false});53 return "A";54 },55 b: "B"56 });57 assertDeepEq(entries, [["a", "A"]]);58 let ownKeysCallCount = 0;59 let getOwnPropertyDescriptorCalls = [];60 let target = { a: 1, b: 2, c: 3 };61 o = new Proxy(target, {62 ownKeys() {63 ownKeysCallCount++;64 return ["c", "a"];65 },66 getOwnPropertyDescriptor(target, key) {67 getOwnPropertyDescriptorCalls.push(key);68 return Object.getOwnPropertyDescriptor(target, key);69 }70 });71 entries = Object.entries(o);72 assertEq(ownKeysCallCount, 1);73 assertDeepEq(entries, [["c", 3], ["a", 1]]);74 assertDeepEq(getOwnPropertyDescriptorCalls, ["c", "a"]);75}76if (typeof reportCompare === "function")...
entries.d.ts
Source:entries.d.ts
...19 // Does some arbitrary processing on the value (with type information available)20 example[1].toFixed()21]);22const example: Example = {someKey: 1};23const entries = Object.entries(example) as Entries<Example>;24const output = manipulatesEntries(entries);25// Objects26const objectExample = {a: 1};27const objectEntries: Entries<typeof objectExample> = [['a', 1]];28// Arrays29const arrayExample = ['a', 1];30const arrayEntries: Entries<typeof arrayExample> = [[0, 'a'], [1, 1]];31// Maps32const mapExample = new Map([['a', 1]]);33const mapEntries: Entries<typeof map> = [['a', 1]];34// Sets35const setExample = new Set(['a', 1]);36const setEntries: Entries<typeof setExample> = [['a', 'a'], [1, 1]];37```...
Routes.ts
Source:Routes.ts
1export const RouteEntries = Object.freeze({2 index: "",3 register: "register",4 accounts: "accounts",5 login: "login",6 dashboard: "admin",7 shoppingCart: "shoppingCart",8 inventory: "inventory",9 orders: "orders",10 itemcatalog: "item",11 myorders: "myorders",12 expenses: "expenses",13 reports: "reports"14 });15 //To be moved to the application layer16 export const Routes = Object.freeze({17 index: RouteEntries.index + "/",18 register: RouteEntries.index + "/" + RouteEntries.register,19 accounts: RouteEntries.index + "/" + RouteEntries.accounts,20 login: RouteEntries.index + "/" + RouteEntries.login,21 dashboard: RouteEntries.index + "/" + RouteEntries.dashboard,22 shoppingCart: RouteEntries.index + "/" + RouteEntries.shoppingCart,23 inventory: RouteEntries.index + "/" + RouteEntries.inventory,24 orders: RouteEntries.index + "/" + RouteEntries.orders,25 itemcatalog: RouteEntries.index + "/" + RouteEntries.itemcatalog,26 myorders: RouteEntries.index + "/" + RouteEntries.myorders,27 expenses: RouteEntries.index + "/" + RouteEntries.expenses,28 reports: RouteEntries.index + "/" + RouteEntries.reports...
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 for (const browserType of ['chromium', 'firefox', 'webkit']) {4 const browser = await playwright[browserType].launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const entries = await page.context().storageState({ path: 'state.json' });8 console.log(entries);9 await browser.close();10 }11})();12{13 {
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const entries = await page.context().storageState({ path: 'state.json' });7 console.log(entries);8 await browser.close();9})();10{11 {
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 const entries = await page.context().storageState({ path: 'state.json' });7 console.log(entries);8 await browser.close();9})();10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch({ headless: false });13 const context = await browser.newContext();14 const page = await context.newPage();15 const entries = await page.context().storageState({ path: 'state.json' });16 console.log(entries);17 await browser.close();18})();19const { chromium } = require('playwright');20(async () => {21 const browser = await chromium.launch({ headless: false });22 const context = await browser.newContext();23 const page = await context.newPage();24 const entries = await page.context().storageState({ path: 'state.json' });25 console.log(entries);26 await browser.close();27})();28const { chromium } = require('playwright');29(async () => {30 const browser = await chromium.launch({ headless: false });31 const context = await browser.newContext();32 const page = await context.newPage();33 const entries = await page.context().storageState({ path: 'state.json' });34 console.log(entries);35 await browser.close();36})();37const { chromium } = require('playwright');38(async () => {39 const browser = await chromium.launch({ headless: false });40 const context = await browser.newContext();41 const page = await context.newPage();42 const entries = await page.context().storageState({ path: 'state.json' });43 console.log(entries);44 await browser.close();45})();
Using AI Code Generation
1(async () => {2 const browser = await chromium.launch();3 const context = await browser.newContext();4 const page = await context.newPage();5 const client = await page.context().newCDPSession(page);6 const entries = await client.send('Performance.getEntries');7 console.log(entries);8 await browser.close();9})();10I am trying to run the above code in the Playwright console (Playwright > Run > Run in console) but I am getting the following error:11const browser = await chromium.launch();12const context = await browser.newContext();13const page = await context.newPage();14await page.waitForLoadState('load');15const performanceTiming = JSON.parse(16 await page.evaluate(() => JSON.stringify(window.performance.timing))17);18console.log(performanceTiming);19I am trying to run the following code in the Playwright console (Playwright > Run > Run in console) but I am getting the following error:20const browser = await chromium.launch();21const context = await browser.newContext();22const page = await context.newPage();23await page.waitForLoadState('load');24const performanceTiming = JSON.parse(25 await page.evaluate(() => JSON.stringify(window.performance.timing))26);27console.log(performanceTiming);28const browser = await chromium.launch();29const context = await browser.newContext();30const page = await context.newPage();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const entries = await page.context().newCDPSession(page).send('Network.getResponseBody', {requestId: 'C1.1'});6 console.log(entries);7 await browser.close();8})();9Error: Protocol error (Network.getResponseBody): No data found for resource with given identifier (C1.1)
Using AI Code Generation
1(async () => {2 const browser = await chromium.launch();3 const context = await browser.newContext();4 const page = await context.newPage();5 const entries = await page.context().routes();6 console.log(entries);7 await browser.close();8})();
Using AI Code Generation
1const { entries } = require('playwright/lib/utils/utils');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 console.log(await entries(page));8 await browser.close();9})();10 {11 },12 {13 }
Using AI Code Generation
1const {chromium} = require('playwright');2const browser = await chromium.launch();3const context = await browser.newContext();4const page = await context.newPage();5const entries = await page.context().storageState({ path: 'state.json' });6console.log(entries);7await browser.close();8{9 {10 }11 {12 {13 }14 }15}16Your name to display (optional):17Your name to display (optional):
Using AI Code Generation
1const { chromium } = require("playwright");2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const entries = await page._client.send("DOM.getDocument", {6 });7 console.log(entries);8 await browser.close();9})();10{11 root: {12 },13 {14 },15 {16 },17 {18 },19 {20 },21 {22 },23 {
Using AI Code Generation
1const { chromium } = require("playwright");2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.route("**", (route) => {7 route.continue();8 });9 await page.screenshot({ path: "example.png" });10 const entries = await page.context().tracing._tracing._entries;11 console.log(entries);12 await browser.close();13})();
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!