Best JavaScript code snippet using wpt
opaque-script-sw.js
Source:opaque-script-sw.js
1importScripts('test-helpers.sub.js');2importScripts('/common/get-host-info.sub.js');3const NAME = 'foo';4const SAME_ORIGIN_BASE = new URL('./', self.location.href).href;5const CROSS_ORIGIN_BASE = new URL('./',6 get_host_info().HTTPS_REMOTE_ORIGIN + base_path()).href;7const urls = [8 `${SAME_ORIGIN_BASE}opaque-script-small.js`,9 `${SAME_ORIGIN_BASE}opaque-script-large.js`,10 `${CROSS_ORIGIN_BASE}opaque-script-small.js`,11 `${CROSS_ORIGIN_BASE}opaque-script-large.js`,12];13self.addEventListener('install', evt => {14 evt.waitUntil(async function() {15 const c = await caches.open(NAME);16 const promises = urls.map(async function(u) {17 const r = await fetch(u, { mode: 'no-cors' });18 await c.put(u, r);19 });20 await Promise.all(promises);21 }());22});23self.addEventListener('fetch', evt => {24 const url = new URL(evt.request.url);25 if (!url.pathname.includes('opaque-script-small.js') &&26 !url.pathname.includes('opaque-script-large.js')) {27 return;28 }29 evt.respondWith(async function() {30 const c = await caches.open(NAME);31 return c.match(evt.request);32 }());...
Using AI Code Generation
1var wsocket = CreateWebSocket(url, ["echo-protocol"]);2wsocket.onopen = testOpen;3wsocket.onmessage = testMessage;4wsocket.onclose = testClose;5function testOpen(evt)6{7 wsocket.send("Hello, world!");8}9function testMessage(evt)10{11 shouldBe("evt.data", "'Hello, world!'");12 wsocket.close();13}14function testClose(evt)15{16 finishJSTest();17}
Using AI Code Generation
1var test = async_test('The user agent should not send cookies on a cross-origin request with credentials set to include.');2test.step(function() {3 var xhr = new XMLHttpRequest();4 xhr.open('GET', SAME_ORIGIN_BASE + '/common/blank.html', true);5 xhr.withCredentials = true;6 xhr.send();7 xhr.onload = test.step_func(function() {8 assert_equals(xhr.getResponseHeader('Set-Cookie'), null);9 test.done();10 });11});
Using AI Code Generation
1var url = SAME_ORIGIN_BASE + "file.txt";2var url = SAME_ORIGIN_BASE + "subdir/file.txt";3var url = SAME_ORIGIN_BASE + "../file.txt";4var url = SAME_ORIGIN_BASE + "../../file.txt";5var url = SAME_ORIGIN_BASE + "../../../file.txt";6var url = SAME_ORIGIN_BASE + "../../../../file.txt";7var url = SAME_ORIGIN_BASE + "../../../../../file.txt";8var url = SAME_ORIGIN_BASE + "../../../../../../file.txt";9var url = SAME_ORIGIN_BASE + "../../../../../../../file.txt";10var url = SAME_ORIGIN_BASE + "../../../../../../../../file.txt";11var url = SAME_ORIGIN_BASE + "../../../../../../../../../file.txt";12var url = SAME_ORIGIN_BASE + "../../../../../../../../../../file.txt";13var url = SAME_ORIGIN_BASE + "../../../../../../../../../../../file.txt";
Using AI Code Generation
1var url = "/security/contentSecurityPolicy/resources/csp-report.py?op=setheader&policy=script-src+unsafe-inline+unsafe-eval";2var sameOriginBase = new SameOriginBase(url);3sameOriginBase.get(function(response) {4 var cspHeader = response.headers["content-security-policy"];5 var policy = "script-src 'self' 'unsafe-inline' 'unsafe-eval'";6 assert_equals(cspHeader, policy, "The header value should be set to " + policy);7 done();8});
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!!