Best JavaScript code snippet using wpt
messages.ts
Source:messages.ts
1import {2 Callback,3 Collection,4 forEach,5 isArrayLike,6 isIterable,7 Resolver,8} from '.';9import { defer, deferTrigger } from './async';10export interface CallbackInit {11 [message: string]: Callback | Collection<Callback>;12}13interface WorkerMessage {14 type: string | number;15 args: any[];16 token?: number;17}18export interface WorkerMessageServiceConnectOptions extends WorkerOptions {19 shared?: boolean;20}21function isSharedWorkerGlobalScope(worker: any): worker is SharedWorkerGlobalScope {22 return self.SharedWorkerGlobalScope && (worker instanceof self.SharedWorkerGlobalScope);23}24export abstract class MessageServiceBase {25 private _callbacks = new Map<string, Set<Callback>>();26 private _resolvers = new Map<number, Resolver<any[]>>();27 private _callbackTokenInc = 0;28 protected _callbackState?: any;29 constructor(callbackInit?: CallbackInit) {30 if (callbackInit != null) this.on(callbackInit);31 }32 public trigger(message: string, ...args: any[]) {33 return this._sendMessage(String(message), args), this;34 }35 public call(message: string, ...args: any[]) {36 return this._sendMessage(String(message), args, true);37 }38 public on(message: string, ...callbacks: Callback[]): this;39 public on(messages: CallbackInit): this;40 public on(m: string | CallbackInit, ...callbacks: Callback[]) {41 if (typeof m !== 'object')42 m = { [m]: callbacks };43 for (const message in m) {44 if (!(message in m) || typeof message !== 'string')45 continue;46 const callback = m[message];47 if (!callback) continue;48 let oCallbacks = this._callbacks.get(message);49 if (typeof callback === 'function') {50 if (!oCallbacks)51 this._callbacks.set(message, oCallbacks = new Set());52 oCallbacks.add(callback);53 continue;54 }55 if (isArrayLike(callback) && !callback.length)56 continue;57 if (!oCallbacks) {58 this._callbacks.set(message, new Set(59 isIterable(callback) ? callback : Array.from(callback),60 ));61 continue;62 }63 forEach(callback, oCallbacks.add, oCallbacks);64 }65 return this;66 }67 public off(message: string, ...callbacks: Callback[]) {68 message = String(message);69 if (!callbacks?.length)70 return this._callbacks.delete(message), this;71 const oCallbacks = this._callbacks.get(message);72 if (oCallbacks?.size)73 callbacks.forEach(oCallbacks.delete, oCallbacks);74 if (!oCallbacks?.size)75 this._callbacks.delete(message);76 return this;77 }78 public dispose() {79 this._callbacks.clear();80 this._resolvers.clear();81 }82 protected _sendMessage(messageOrToken: string | number, args: any[]): void;83 protected _sendMessage(84 message: string,85 args: any[],86 requireCallback: true,87 ): Promise<any[]>;88 protected _sendMessage(89 messageOrToken: string | number,90 args: any[],91 requireCallback?: boolean,92 ): Promise<any[]> | undefined;93 protected _sendMessage(id: string | number, args: any[], requireCallback?: boolean) {94 if (!requireCallback || typeof id === 'number')95 return void this._sendMessageImpl(id, args);96 const message = id;97 return new Promise((resolve, reject) => {98 const callbackToken = ++this._callbackTokenInc;99 this._resolvers.set(callbackToken, { resolve, reject });100 try {101 this._sendMessageImpl(message, args, callbackToken);102 } catch (error) {103 reject(error);104 this._resolvers.delete(callbackToken);105 }106 });107 }108 protected abstract _sendMessageImpl(109 messageOrToken: string | number,110 args: any[],111 callbackToken?: number,112 ): void;113 protected _handleReceivedMessage(114 messageOrToken: string | number,115 args: any[],116 callbackToken?: number,117 ) {118 switch (typeof messageOrToken) {119 case 'string': {120 const callbacks = this._callbacks.get(messageOrToken);121 if (!callbacks?.size) {122 if (callbackToken != null)123 this._sendMessage(callbackToken, [124 new Error(`Message ${messageOrToken} is not registered.`),125 ]);126 break;127 }128 const { _callbackState } = this;129 if (callbackToken != null)130 Promise.all(Array.from(callbacks).map(cb => defer(cb, _callbackState, args))).then(131 value => this._sendMessage(callbackToken, [null, value]),132 error => this._sendMessage(callbackToken, [error]),133 );134 else135 callbacks.forEach(cb => deferTrigger(cb, _callbackState, args));136 break;137 }138 case 'number': {139 const resolver = this._resolvers.get(messageOrToken);140 if (resolver == null) break;141 this._resolvers.delete(messageOrToken);142 if (args.length < 2) resolver.reject(args[0]);143 else resolver.resolve(args[1]);144 break;145 }146 }147 }148}149export class LoopbackMessageService extends MessageServiceBase {150 protected _sendMessageImpl(id: string | number, args: any[], callbackToken?: number) {151 return this._handleReceivedMessage(id, args, callbackToken);152 }153}154export class WorkerMessageService extends MessageServiceBase {155 private _sendTransfers = new WeakMap<any[], Collection<Transferable>>();156 private _callbackTransfers = new Map<number, Iterable<Transferable>>();157 private _ports?: Set<MessagePort>;158 private _callbackMapping?: Map<number, MessagePort>;159 public static get host() {160 return new WorkerMessageService(161 self as DedicatedWorkerGlobalScope | SharedWorkerGlobalScope,162 );163 }164 public static to(165 path: string,166 options?: WorkerMessageServiceConnectOptions,167 callbackInit?: CallbackInit,168 ) {169 return new WorkerMessageService(170 options?.shared ?171 new SharedWorker(path, options).port :172 new Worker(path, options),173 callbackInit,174 );175 }176 public constructor(177 public worker:178 Worker | MessagePort |179 DedicatedWorkerGlobalScope |180 SharedWorkerGlobalScope,181 callbackInit?: CallbackInit,182 ) {183 super(callbackInit);184 const { constructor } = Object.getPrototypeOf(this);185 if (constructor === WorkerMessageService && worker === self)186 Object.defineProperty(constructor, 'host', { value: this, configurable: true });187 this._receiveMessageImpl = this._receiveMessageImpl.bind(this);188 if (isSharedWorkerGlobalScope(worker)) {189 this._callbackMapping = new Map();190 this._ports = new Set();191 this._connectImpl = this._connectImpl.bind(this);192 worker.addEventListener('connect', this._connectImpl);193 } else {194 worker.addEventListener('message', this._receiveMessageImpl as EventListener);195 if (worker instanceof MessagePort) worker.start();196 }197 }198 public callAndTransfer(199 message: string,200 args: any[],201 transfer?: Collection<Transferable>,202 isTrigger?: false,203 ): Promise<any[]>;204 public callAndTransfer(205 message: string,206 args: any[],207 transfer: Collection<Transferable> | undefined,208 isTrigger: true,209 ): void;210 public callAndTransfer(211 message: string,212 args: any[],213 transfer?: Collection<Transferable>,214 isTrigger?: boolean,215 ): Promise<any[]> | undefined;216 public callAndTransfer(217 message: string,218 args: any[],219 transfer?: Collection<Transferable>,220 isTrigger?: boolean,221 ) {222 if (transfer != null) this._sendTransfers.set(args, transfer);223 return this._sendMessage(String(message), args, !isTrigger);224 }225 public dispose() {226 super.dispose();227 delete this._callbackState;228 this._callbackTransfers.clear();229 if (isSharedWorkerGlobalScope(this.worker)) {230 if (this._ports?.size) {231 for (const port of this._ports) {232 port.removeEventListener('message', this._receiveMessageImpl);233 port.close();234 }235 this._ports.clear();236 }237 this.worker.removeEventListener('connect', this._connectImpl);238 } else {239 this.worker.removeEventListener('message', this._receiveMessageImpl as EventListener);240 if (this.worker instanceof MessagePort) this.worker.close();241 }242 if (WorkerMessageService.host === this)243 Object.defineProperty(WorkerMessageService, 'host', {244 value: undefined,245 configurable: true,246 });247 }248 protected _connectImpl(e: MessageEvent) {249 if (!isSharedWorkerGlobalScope(this.worker) || !this._ports || !e.ports?.length)250 return;251 for (const port of e.ports) {252 if (this._ports.has(port))253 continue;254 port.addEventListener('message', this._receiveMessageImpl);255 port.start();256 this._ports.add(port);257 }258 }259 protected _receiveMessageImpl(e: MessageEvent<WorkerMessage>) {260 if (e.data == null) return;261 const { type, args, token } = e.data;262 switch (typeof type) {263 case 'number':264 const transfer = new Set<Transferable>();265 this._callbackState = { transfer };266 this._callbackTransfers.set(type, transfer);267 break;268 case 'string':269 if (isSharedWorkerGlobalScope(this.worker) && token != null && (e.source instanceof MessagePort))270 this._callbackMapping?.set(token, e.source);271 break;272 }273 try {274 return this._handleReceivedMessage(type, args, token);275 } finally {276 delete this._callbackState;277 }278 }279 protected _sendMessageImpl(type: string | number, args: any[], token?: number) {280 let transfer: Collection<Transferable> | undefined;281 try {282 let { worker } = this;283 switch (typeof type) {284 case 'number':285 if (isSharedWorkerGlobalScope(worker)) {286 const port = this._callbackMapping?.get(type);287 if (!port) return;288 worker = port;289 this._callbackMapping!.delete(type);290 }291 if (args[0] instanceof Error) {292 const { message, stack } = args[0];293 args[0] = { message, stack };294 }295 transfer = this._callbackTransfers.get(type);296 break;297 case 'string':298 if (isSharedWorkerGlobalScope(worker))299 throw new Error('Not supported operation.');300 transfer = this._sendTransfers.get(args);301 break;302 }303 return worker.postMessage(304 { type, args, token } as WorkerMessage,305 transfer != null ? Array.isArray(transfer) ?306 transfer : Array.from(transfer) : [],307 );308 } finally {309 if (transfer != null)310 switch (typeof type) {311 case 'number': this._callbackTransfers.delete(type); break;312 case 'string': this._sendTransfers.delete(args); break;313 }314 }315 }...
port.js
Source:port.js
1// Chrome to Safari port2// Author: Michael Gundlach (gundlach@gmail.com)3// License: GPLv3 as part of adblockforchrome.googlecode.com4// or MIT if GPLv3 conflicts with your code's license.5//6// Porting library to make Chrome extensions work in Safari.7// To use: Add as the first script loaded in your Options page,8// your background page, your Chrome manifest.json, and your9// Safari Info.plist (created by the Extensions Builder).10//11// Then you can use chrome.* APIs as usual, and check the SAFARI12// global boolean variable to see if you're in Safari or Chrome13// for doing browser-specific stuff. The safari.* APIs will 14// still be available in Safari, and the chrome.* APIs will be15// unchanged in Chrome.16try {17 chrome.extension.getURL; // verify 'extension' property exists18 SAFARI = false;19}20catch (e) {21 SAFARI = true;22}23if (SAFARI) {24 // Replace the 'chrome' object with a Safari adapter.25 chrome = {26 // Track tabs that make requests to the global page, assigning them27 // IDs so we can recognize them later.28 __getTabId: (function() {29 // Tab objects are destroyed when no one has a reference to them,30 // so we keep a list of them, lest our IDs get lost.31 var tabs = [];32 var lastAssignedTabId = 0;33 var theFunction = function(tab) {34 // Clean up closed tabs, to avoid memory bloat.35 tabs = tabs.filter(function(t) { return t.browserWindow != null; });36 if (tab.id == undefined) {37 // New tab38 tab.id = lastAssignedTabId + 1;39 lastAssignedTabId = tab.id;40 tabs.push(tab); // save so it isn't garbage collected, losing our ID.41 }42 return tab.id;43 };44 return theFunction;45 })(),46 extension: {47 getURL: function(path) { 48 return safari.extension.baseURI + path;49 },50 sendRequest: (function() {51 // The function we'll return at the end of all this52 function theFunction(data, callback) {53 var callbackToken = "callback" + Math.random();54 // Listen for a response for our specific request token.55 addOneTimeResponseListener(callbackToken, callback);56 safari.self.tab.dispatchMessage("request", {57 data: data,58 callbackToken: callbackToken59 });60 }61 // Make a listener that, when it hears sendResponse for the given 62 // callbackToken, calls callback(resultData) and deregisters the 63 // listener.64 function addOneTimeResponseListener(callbackToken, callback) {65 var responseHandler = function(messageEvent) {66 if (messageEvent.name != "response")67 return;68 if (messageEvent.message.callbackToken != callbackToken)69 return;70 // Workaround to try to fix a crashing bug in Safari for Mac where there is no callback71 if ((typeof callback === 'undefined') || !callback)72 {}73 else74 callback(messageEvent.message.data);75 // Change to calling in 0-ms setTimeout, as Safari team thinks76 // this will work around their crashing until they can release77 // a fix.78 // safari.self.removeEventListener("message", responseHandler, false);79 window.setTimeout(function() {80 safari.self.removeEventListener("message", responseHandler, false);81 }, 0);82 };83 safari.self.addEventListener("message", responseHandler, false);84 }85 return theFunction;86 })(),87 onRequest: {88 addListener: function(handler) {89 safari.application.addEventListener("message", function(messageEvent) {90 // Only listen for "sendRequest" messages91 if (messageEvent.name != "request")92 return;93 var request = messageEvent.message.data;94 var id = chrome.__getTabId(messageEvent.target);95 // Added in the url for the sender since Google Chrome has that. Also added in the target because Safari uses that a lot in extensions.96 var sender = { tab: { id: id, url: messageEvent.target.url }, target: messageEvent.target}; 97 var sendResponse = function(dataToSend) {98 var responseMessage = { callbackToken: messageEvent.message.callbackToken, data: dataToSend };99 messageEvent.target.page.dispatchMessage("response", responseMessage);100 }101 handler(request, sender, sendResponse);102 }, false);103 },104 },105 connect: function(port_data) {106 var portUuid = "portUuid" + Math.random();107 safari.self.tab.dispatchMessage("port-create", {name: port_data.name, uuid: portUuid});108 var newPort = {109 name: port_data.name,110 onMessage: { 111 addListener: function(listener) {112 safari.self.addEventListener("message", function(messageEvent) {113 // If the message was a port.postMessage to our port, notify our listener.114 if (messageEvent.name != "port-postMessage") 115 return;116 if (messageEvent.message.portUuid != portUuid)117 return;118 listener(messageEvent.message.data);119 });120 } 121 }122 };123 return newPort;124 },125 onConnect: {126 addListener: function(handler) {127 // Listen for port creations128 safari.application.addEventListener("message", function(messageEvent) {129 if (messageEvent.name != "port-create")130 return;131 var portName = messageEvent.message.name;132 var portUuid = messageEvent.message.uuid;133 var id = chrome.__getTabId(messageEvent.target);134 var newPort = {135 name: portName,136 sender: { tab: { id: id } },137 onDisconnect: { 138 addListener: function() { 139 console.log("CHROME PORT LIBRARY: chrome.extension.onConnect.addListener: port.onDisconnect is not implemented, so I'm doing nothing.");140 }141 },142 postMessage: function(data) {143 if (! messageEvent.target.page) {144 console.log("Oops, this port has already disappeared -- cancelling.");145 return;146 }147 messageEvent.target.page.dispatchMessage("port-postMessage", { portUuid: portUuid, data: data });148 }149 };150 // Inform the onNewPort caller about the new port151 handler(newPort);152 });153 }154 },155 onRequestExternal: {156 addListener: function() {157 console.log("CHROME PORT LIBRARY: onRequestExternal not supported.");158 }159 }160 }161 };...
index.js
Source:index.js
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19var app = {20 // Application Constructor21 initialize: function() {22 this.bindEvents();23 },24 // Bind Event Listeners25 //26 // Bind any events that are required on startup. Common events are:27 // 'load', 'deviceready', 'offline', and 'online'.28 bindEvents: function() {29 document.addEventListener('deviceready', this.onDeviceReady, false);30 },31 // deviceready Event Handler32 //33 // The scope of 'this' is the event. In order to call the 'receivedEvent'34 // function, we must explicity call 'app.receivedEvent(...);'35 onDeviceReady: function() {36 app.receivedEvent('deviceready');37 },38 // Update DOM on a Received Event39 receivedEvent: function(id) {40 var parentElement = document.getElementById(id);41 var listeningElement = parentElement.querySelector('.listening');42 var receivedElement = parentElement.querySelector('.received');43 listeningElement.setAttribute('style', 'display:none;');44 receivedElement.setAttribute('style', 'display:block;');45 console.log('Received Event: ' + id);46 app.testPluginCalls();47 },48 testPluginCalls: function() {49 if (community && community.extractZipFile) {50 // -----------------51 // EXAMPLE USAGE ---52 // The ExtractZIPFile specific code follows53 var onReturn = function(status) {54 var pass = false;55 switch (status.callbackToken) {56 case "1":57 pass = status.entries == 1 && status.files == 1;58 break;59 case "2":60 pass = status.entries == 10 && status.files == 761 && status.directories == 3;62 break;63 case "3":64 pass = status.result == 1;65 break;66 case "4":67 pass = status.entries == 1 && status.files == 1;68 break;69 case "5":70 pass = status.result == 1;71 break;72 case "6":73 pass = status.result == 1;74 break;75 case "7":76 pass = status.result == 1;77 break;78 case "8":79 pass = status.result == 1;80 break;81 case "9":82 pass = status.result == 1;83 break;84 case "10":85 pass = status.result == -1; // negative test86 break;87 case "11":88 pass = status.result == 1;89 break;90 }91 var pass_msg = "failed";92 if (pass == true)93 pass_msg = "passed";94 app.writeOut("\nTest " + status.callbackToken + " " + pass_msg);95 app.writeOut("Full Status: " + JSON.stringify(status, null, " "));96 };97 community.extractZipFile.extract(98 {99 zip: "./app/native/res/zip/test_single-file-no-folder.zip",100 destination: "./tmp/test1test1/",101 callbackToken: "1"102 },103 onReturn104 );105 community.extractZipFile.extract(106 {107 zip: "./app/native/res/zip/test_multi-file-multi-folder.zip",108 destination: "./tmp/tttttt/",109 callbackToken: "2"110 },111 onReturn112 );113 community.extractZipFile.compress( 114 { 115 filePath: "./app/native/res/zip/test_single_file_compression.txt",116 zipDestinationPath: "./tmp/compressed_test/zip_test.zip",117 callbackToken: "3"118 },119 onReturn120 );121 community.extractZipFile.extract(122 {123 zip: "./tmp/compressed_test/zip_test.zip",124 destination: "./tmp/compressed_test/",125 callbackToken: "4"126 },127 onReturn128 );129 130 community.extractZipFile.compress( //zip 3 files, no directory131 { 132 filePath: "./app/native/res/zip/aaaa.txt:./app/native/res/zip/bbbb.txt:./app/native/res/zip/cccc.txt", 133 zipDestinationPath: "./tmp/case/folder123.zip",134 callbackToken: "5"135 },136 onReturn137 );138 139 community.extractZipFile.compress( //zip 1 file, 1 directory with 1 file in it140 { 141 filePath: "./app/native/res/zip/aaaa.txt:./app/native/res/zip/3", 142 zipDestinationPath: "./tmp/case/folder333.zip",143 callbackToken: "6"144 },145 onReturn146 );147 community.extractZipFile.compress( //zip 1 file, 1 directory with 1 file and 1 directory which has a file in it 148 { 149 filePath: "./app/native/res/zip/aaaa.txt:./app/native/res/zip/2", 150 zipDestinationPath: "./tmp/case/folder444.zip",151 callbackToken: "7"152 },153 onReturn154 );155 community.extractZipFile.compress( //zip 1 directory with 1 file and 1 directory which have a file and a directory which have a file and a directory in it 156 { 157 filePath: "./app/native/res/zip/5", 158 zipDestinationPath: "./tmp/case/folder888.zip",159 callbackToken: "8"160 },161 onReturn162 );163 community.extractZipFile.compress( //zip 1 directory with 2 files and 3 directories which have a file in each 164 { 165 filePath: "./app/native/res/zip/4", 166 zipDestinationPath: "./tmp/case/folder999.zip",167 callbackToken: "9"168 },169 onReturn170 );171 community.extractZipFile.compress( //zip one file with incorrect path; expect fail since no zip created172 {173 filePath: "./app/native/res/zip/noSuchFile",174 zipDestinationPath: "./tmp/case/floder361.zip",175 callbackToken: "10"176 },177 onReturn178 );179 community.extractZipFile.compress( //zip multiple files with at least 1 file does not exist180 {181 filePath: "./app/noThisFile:./app/native/res/zip/2:./app/noThatFile",182 zipDestinationPath: "./tmp/case/floder361.zip",183 callbackToken: "11"184 },185 onReturn186 );187 // END EXAMPLE USAGE188 // -----------------189 } else {190 app.writeOut("Plugin was not found");191 }192 },193 writeOut: function(message) {194 var output = document.getElementById('results');195 output.innerText = output.innerText + message;196 output.appendChild(document.createElement('br'));197 console.log(message);198 }...
Using AI Code Generation
1var wpt = require('wpt-api');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1b2c3d4e5f6g7h8i9j0');3var testId = '12345678';4wpt.callbackToken(testId, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('wpt-api');12var wpt = new WebPageTest('www.webpagetest.org', 'A.1b2c3d4e5f6g7h8i9j0');13wpt.getLocations(function(err, data) {14 if (err) {15 console.log(err);16 } else {17 console.log(data);18 }19});20var wpt = require('wpt-api');21var wpt = new WebPageTest('www.webpagetest.org', 'A.1b2c3d4e5f6g7h8i9j0');22wpt.getTesters(function(err, data) {23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28});29var wpt = require('wpt-api');30var wpt = new WebPageTest('www.webpagetest.org', 'A.1b2c3d4e5f6g7h8i9j0');31wpt.getTesters(function(err, data) {32 if (err) {33 console.log(err);34 } else {35 console.log(data);36 }37});38var wpt = require('wpt-api');39var wpt = new WebPageTest('www.webpagetest.org', 'A.1b2c3d4e5f6g7h8i9j0');40var testId = '12345678';41wpt.getTestStatus(testId, function(err, data) {42 if (
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.0b0c0d0e0f0g0h0i0j0k0l0m0n0o0p0q0r0s0t0u0v0w0x0y0z');3 if(err) {4 console.log(err);5 } else {6 wpt.callbackToken(data.data.testId, function(err, data) {7 if(err) {8 console.log(err);9 } else {10 console.log(data);11 }12 });13 }14});15var wpt = require('wpt');16var wpt = new WebPageTest('www.webpagetest.org', 'A.0b0c0d0e0f0g0h0i0j0k0l0m0n0o0p0q0r0s0t0u0v0w0x0y0z');17wpt.getLocations(function(err, data) {18 if(err) {19 console.log(err);20 } else {21 console.log(data);22 }23});24var wpt = require('wpt');25var wpt = new WebPageTest('www.webpagetest.org', 'A.0b0c0d0e0f0g0h0i0j0k0l0m0n0o0p0q0r0s0t0u0v0w0x0y0z');26wpt.getTesters(function(err, data) {27 if(err)
Using AI Code Generation
1var wpt = require('webpagetest');2var webpagetest = new wpt('API_KEY');3webpagetest.runTest(testUrl, {callback: callbackUrl}, function(err, data) {4 if(err) {5 console.log('Error: ' + err);6 } else {7 console.log('Test Status: ' + data.statusCode);8 console.log('Test ID: ' + data.data.testId);9 }10});
Using AI Code Generation
1var WebPageTest = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('Test ID: ' + data.data.testId);7 console.log('Test URL: ' + data.data.userUrl);8 }9});10var WebPageTest = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');12wpt.getTestResults('123456_1', function(err, data) {13 if (err) {14 console.log('Error: ' + err);15 } else {16 console.log('Test ID: ' + data.data.testId);17 console.log('Test URL: ' + data.data.userUrl);18 }19});20var WebPageTest = require('webpagetest');21var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');22 if (err) {23 console.log('Error: ' + err);24 } else {25 console.log('Test ID: ' + data.data.testId);26 console.log('Test URL: ' + data.data.userUrl);27 }28});29var WebPageTest = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!