Best JavaScript code snippet using wpt
dedicated-worker.https.window.js
Source:dedicated-worker.https.window.js
1// META: timeout=long2// META: script=/common/get-host-info.sub.js3// META: script=/common/utils.js4// META: script=/common/dispatcher/dispatcher.js5// META: script=./resources/common.js6const same_origin = get_host_info().HTTPS_ORIGIN;7const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;8const cookie_key = "credentialless_dedicated_worker";9const cookie_same_origin = "same_origin";10const cookie_cross_origin = "cross_origin";11promise_test(async test => {12 await Promise.all([13 setCookie(same_origin, cookie_key, cookie_same_origin +14 cookie_same_site_none),15 setCookie(cross_origin, cookie_key, cookie_cross_origin +16 cookie_same_site_none),17 ]);18 // One window with COEP:none. (control)19 const w_control_token = token();20 const w_control_url = same_origin + executor_path +21 coep_none + `&uuid=${w_control_token}`22 const w_control = window.open(w_control_url);23 add_completion_callback(() => w_control.close());24 // One window with COEP:credentialless. (experiment)25 const w_credentialless_token = token();26 const w_credentialless_url = same_origin + executor_path +27 coep_credentialless + `&uuid=${w_credentialless_token}`;28 const w_credentialless = window.open(w_credentialless_url);29 add_completion_callback(() => w_credentialless.close());30 let GetCookie = (response) => {31 const headers_credentialless = JSON.parse(response);32 return parseCookies(headers_credentialless)[cookie_key];33 }34 const dedicatedWorkerTest = function(35 description, origin, coep_for_worker,36 expected_cookies_control,37 expected_cookies_credentialless)38 {39 promise_test_parallel(async t => {40 // Create workers for both window.41 const worker_token_1 = token();42 const worker_token_2 = token();43 // Used to check for errors creating the DedicatedWorker.44 const worker_error_1 = token();45 const worker_error_2 = token();46 const w_worker_src_1 = same_origin + executor_worker_path +47 coep_for_worker + `&uuid=${worker_token_1}`;48 send(w_control_token, `49 new Worker("${w_worker_src_1}", {});50 worker.onerror = () => {51 send("${worker_error_1}", "Worker blocked");52 }53 `);54 const w_worker_src_2 = same_origin + executor_worker_path +55 coep_for_worker + `&uuid=${worker_token_2}`;56 send(w_credentialless_token, `57 const worker = new Worker("${w_worker_src_2}", {});58 worker.onerror = () => {59 send("${worker_error_2}", "Worker blocked");60 }61 `);62 // Fetch resources with the workers.63 const request_token_1 = token();64 const request_token_2 = token();65 const request_url_1 = showRequestHeaders(origin, request_token_1);66 const request_url_2 = showRequestHeaders(origin, request_token_2);67 send(worker_token_1, `68 fetch("${request_url_1}", {mode: 'no-cors', credentials: 'include'})69 `);70 send(worker_token_2, `71 fetch("${request_url_2}", {mode: 'no-cors', credentials: 'include'});72 `);73 const response_control = await Promise.race([74 receive(worker_error_1),75 receive(request_token_1).then(GetCookie)76 ]);77 assert_equals(response_control,78 expected_cookies_control,79 "coep:none => ");80 const response_credentialless = await Promise.race([81 receive(worker_error_2),82 receive(request_token_2).then(GetCookie)83 ]);84 assert_equals(response_credentialless,85 expected_cookies_credentialless,86 "coep:credentialless => ");87 }, `fetch ${description}`)88 };89 dedicatedWorkerTest("same-origin + credentialless worker",90 same_origin, coep_credentialless,91 cookie_same_origin,92 cookie_same_origin);93 dedicatedWorkerTest("same-origin",94 same_origin, coep_none,95 cookie_same_origin,96 "Worker blocked");97 dedicatedWorkerTest("cross-origin",98 cross_origin, coep_none,99 cookie_cross_origin,100 "Worker blocked");101 dedicatedWorkerTest("cross-origin + credentialless worker",102 cross_origin, coep_credentialless,103 undefined,104 undefined);...
dedicated-worker.tentative.https.window.js
Source:dedicated-worker.tentative.https.window.js
1// META: timeout=long2// META: script=/common/get-host-info.sub.js3// META: script=/common/utils.js4// META: script=/common/dispatcher/dispatcher.js5// META: script=./resources/common.js6const same_origin = get_host_info().HTTPS_ORIGIN;7const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;8const cookie_key = "credentialless_dedicated_worker";9const cookie_same_origin = "same_origin";10const cookie_cross_origin = "cross_origin";11promise_test(async test => {12 await Promise.all([13 setCookie(same_origin, cookie_key, cookie_same_origin +14 cookie_same_site_none),15 setCookie(cross_origin, cookie_key, cookie_cross_origin +16 cookie_same_site_none),17 ]);18 // One window with COEP:none. (control)19 const w_control_token = token();20 const w_control_url = same_origin + executor_path +21 coep_none + `&uuid=${w_control_token}`22 const w_control = window.open(w_control_url);23 add_completion_callback(() => w_control.close());24 // One window with COEP:credentialless. (experiment)25 const w_credentialless_token = token();26 const w_credentialless_url = same_origin + executor_path +27 coep_credentialless + `&uuid=${w_credentialless_token}`;28 const w_credentialless = window.open(w_credentialless_url);29 add_completion_callback(() => w_credentialless.close());30 let GetCookie = (response) => {31 const headers_credentialless = JSON.parse(response);32 return parseCookies(headers_credentialless)[cookie_key];33 }34 const dedicatedWorkerTest = function(35 description, origin, coep_for_worker,36 expected_cookies_control,37 expected_cookies_credentialless)38 {39 promise_test_parallel(async t => {40 // Create workers for both window.41 const worker_token_1 = token();42 const worker_token_2 = token();43 // Used to check for errors creating the DedicatedWorker.44 const worker_error_1 = token();45 const worker_error_2 = token();46 const w_worker_src_1 = same_origin + executor_worker_path +47 coep_for_worker + `&uuid=${worker_token_1}`;48 send(w_control_token, `49 new Worker("${w_worker_src_1}", {});50 worker.onerror = () => {51 send("${worker_error_1}", "Worker blocked");52 }53 `);54 const w_worker_src_2 = same_origin + executor_worker_path +55 coep_for_worker + `&uuid=${worker_token_2}`;56 send(w_credentialless_token, `57 const worker = new Worker("${w_worker_src_2}", {});58 worker.onerror = () => {59 send("${worker_error_2}", "Worker blocked");60 }61 `);62 // Fetch resources with the workers.63 const request_token_1 = token();64 const request_token_2 = token();65 const request_url_1 = showRequestHeaders(origin, request_token_1);66 const request_url_2 = showRequestHeaders(origin, request_token_2);67 send(worker_token_1, `68 fetch("${request_url_1}", {mode: 'no-cors', credentials: 'include'})69 `);70 send(worker_token_2, `71 fetch("${request_url_2}", {mode: 'no-cors', credentials: 'include'});72 `);73 const response_control = await Promise.race([74 receive(worker_error_1),75 receive(request_token_1).then(GetCookie)76 ]);77 assert_equals(response_control,78 expected_cookies_control,79 "coep:none => ");80 const response_credentialless = await Promise.race([81 receive(worker_error_2),82 receive(request_token_2).then(GetCookie)83 ]);84 assert_equals(response_credentialless,85 expected_cookies_credentialless,86 "coep:credentialless => ");87 }, `fetch ${description}`)88 };89 dedicatedWorkerTest("same-origin + credentialless worker",90 same_origin, coep_credentialless,91 cookie_same_origin,92 cookie_same_origin);93 dedicatedWorkerTest("same-origin",94 same_origin, coep_none,95 cookie_same_origin,96 "Worker blocked");97 dedicatedWorkerTest("cross-origin",98 cross_origin, coep_none,99 cookie_cross_origin,100 "Worker blocked");101 dedicatedWorkerTest("cross-origin + credentialless worker",102 cross_origin, coep_credentialless,103 undefined,104 undefined);...
shared-worker.https.window.js
Source:shared-worker.https.window.js
1// META: timeout=long2// META: script=/common/get-host-info.sub.js3// META: script=/common/utils.js4// META: script=/common/dispatcher/dispatcher.js5// META: script=./resources/common.js6const same_origin = get_host_info().HTTPS_ORIGIN;7const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;8const cookie_key = "credentialless_shared_worker";9const cookie_same_origin = "same_origin";10const cookie_cross_origin = "cross_origin";11promise_test(async test => {12 await Promise.all([13 setCookie(same_origin, cookie_key, cookie_same_origin +14 cookie_same_site_none),15 setCookie(cross_origin, cookie_key, cookie_cross_origin +16 cookie_same_site_none),17 ]);18 // One window with COEP:none. (control)19 const w_control_token = token();20 const w_control_url = same_origin + executor_path +21 coep_none + `&uuid=${w_control_token}`22 const w_control = window.open(w_control_url);23 add_completion_callback(() => w_control.close());24 // One window with COEP:credentialless. (experiment)25 const w_credentialless_token = token();26 const w_credentialless_url = same_origin + executor_path +27 coep_credentialless + `&uuid=${w_credentialless_token}`;28 const w_credentialless = window.open(w_credentialless_url);29 add_completion_callback(() => w_credentialless.close());30 let GetCookie = (response) => {31 const headers_credentialless = JSON.parse(response);32 return parseCookies(headers_credentialless)[cookie_key];33 }34 const sharedWorkerTest = function(35 description, origin, coep_for_worker,36 expected_cookies_control,37 expected_cookies_credentialless)38 {39 promise_test_parallel(async t => {40 // Create workers for both window.41 const worker_token_1 = token();42 const worker_token_2 = token();43 // Used to check for errors creating the DedicatedWorker.44 const worker_error_1 = token();45 const worker_error_2 = token();46 const w_worker_src_1 = same_origin + executor_worker_path +47 coep_for_worker + `&uuid=${worker_token_1}`;48 send(w_control_token, `49 let worker = new SharedWorker("${w_worker_src_1}", {});50 worker.onerror = () => {51 send("${worker_error_1}", "Worker blocked");52 }53 `);54 const w_worker_src_2 = same_origin + executor_worker_path +55 coep_for_worker + `&uuid=${worker_token_2}`;56 send(w_credentialless_token, `57 let worker = new SharedWorker("${w_worker_src_2}", {});58 worker.onerror = () => {59 send("${worker_error_2}", "Worker blocked");60 }61 `);62 // Fetch resources with the workers.63 const request_token_1 = token();64 const request_token_2 = token();65 const request_url_1 = showRequestHeaders(origin, request_token_1);66 const request_url_2 = showRequestHeaders(origin, request_token_2);67 send(worker_token_1,68 `fetch("${request_url_1}", {mode: 'no-cors', credentials: 'include'})`);69 send(worker_token_2,70 `fetch("${request_url_2}", {mode: 'no-cors', credentials: 'include'})`);71 const response_control = await Promise.race([72 receive(worker_error_1),73 receive(request_token_1).then(GetCookie)74 ]);75 assert_equals(response_control,76 expected_cookies_control,77 "coep:none => ");78 const response_credentialless = await Promise.race([79 receive(worker_error_2),80 receive(request_token_2).then(GetCookie)81 ]);82 assert_equals(response_credentialless,83 expected_cookies_credentialless,84 "coep:credentialless => ");85 }, `fetch ${description}`)86 };87 sharedWorkerTest("same-origin",88 same_origin, coep_none,89 cookie_same_origin,90 cookie_same_origin);91 sharedWorkerTest("same-origin + credentialless worker",92 same_origin, coep_credentialless,93 cookie_same_origin,94 cookie_same_origin);95 sharedWorkerTest("cross-origin",96 cross_origin, coep_none,97 cookie_cross_origin,98 cookie_cross_origin);99 sharedWorkerTest("cross-origin + credentialless worker",100 cross_origin, coep_credentialless,101 undefined,102 undefined);...
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var request = require('request');4var cheerio = require('cheerio');5var jsonfile = require('jsonfile');6var file = 'output.json';7var obj = {8};9wptools.request_token_1('wikipedia', 'en', 'Wikipedia', function (err, res) {10 if (err) {11 console.log(err);12 } else {13 console.log(res);14 }15});16wptools.request_token_2('wikipedia', 'en', 'Wikipedia', function (err, res) {17 if (err) {18 console.log(err);19 } else {20 console.log(res);21 }22});23wptools.request_token_3('wikipedia', 'en', 'Wikipedia', function (err, res) {24 if (err) {25 console.log(err);26 } else {27 console.log(res);28 }29});30wptools.request_token_4('wikipedia', 'en', 'Wikipedia', function (err, res) {31 if (err) {32 console.log(err);33 } else {34 console.log(res);35 }36});37wptools.request_token_5('wikipedia', 'en', 'Wikipedia', function (err, res) {38 if (err) {39 console.log(err);40 } else {41 console.log(res);42 }43});44wptools.request_token_6('wikipedia', 'en', 'Wikipedia', function (err, res) {45 if (err) {46 console.log(err);47 } else {48 console.log(res);49 }50});51wptools.request_token_7('wikipedia', 'en', 'Wikipedia', function (err, res) {52 if (err) {53 console.log(err);54 } else {55 console.log(res);56 }57});
Using AI Code Generation
1var wpt = require('wpt-api');2var options = {3};4wpt.request_token_1(options, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('wpt-api');12var options = {13};14wpt.request_token_2(options, function(err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21var wpt = require('wpt-api');22var options = {23};24wpt.request_token_3(options, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});
Using AI Code Generation
1var request = require('request');2var fs = require('fs');3var util = require('util');4var wpt = require('webpagetest');5var wpt = new wpt('www.webpagetest.org');6var cheerio = require('cheerio');7var async = require('async');8var request = require('request');9var fs = require('fs');10var util = require('util');11var wpt = require('webpagetest');12var wpt = new wpt('www.webpagetest.org');13var cheerio = require('cheerio');14var async = require('async');15var request = require('request');16var fs = require('fs');17var util = require('util');18var wpt = require('webpagetest');19var wpt = new wpt('www.webpagetest.org');20var cheerio = require('cheerio');21var async = require('async');22var request = require('request');23var fs = require('fs');24var util = require('util');25var wpt = require('webpagetest');26var wpt = new wpt('www.webpagetest.org');27var cheerio = require('cheerio');28var async = require('async');29var request = require('request');30var fs = require('fs');31var util = require('util');32var wpt = require('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!!