Best JavaScript code snippet using wpt
nel.sub.js
Source:nel.sub.js
...42 } else {43 return "{{hosts[alt][]}}"44 }45}46function _getNELResourceURL(subdomain, suffix) {47 return "https://" + _monitoredDomain(subdomain) +48 ":{{ports[https][0]}}/network-error-logging/support/" + suffix;49}50/*51 * Fetches a resource whose headers define a basic NEL policy (i.e., with no52 * include_subdomains flag). We ensure that we request the resource from a53 * different origin than is used for the main test case HTML file or for report54 * uploads. This minimizes the number of reports that are generated for this55 * policy.56 */57function getURLForResourceWithBasicPolicy(subdomain) {58 return _getNELResourceURL(subdomain, "pass.png?id="+reportID+"&success_fraction=1.0");59}60function fetchResourceWithBasicPolicy(subdomain) {61 const url = getURLForResourceWithBasicPolicy(subdomain);62 return fetch(url, {mode: "no-cors"});63}64function fetchResourceWithZeroSuccessFractionPolicy(subdomain) {65 const url = _getNELResourceURL(subdomain, "pass.png?id="+reportID+"&success_fraction=0.0");66 return fetch(url, {mode: "no-cors"});67}68/*69 * Similar to the above methods, but fetch resources in an iframe. Allows matching70 * full context of reports sent from an iframe that's same-site relative to the domains71 * a policy set.72 */73 function loadResourceWithBasicPolicyInIframe(subdomain) {74 return loadResourceWithPolicyInIframe(75 getURLForResourceWithBasicPolicy(subdomain));76}77function loadResourceWithZeroSuccessFractionPolicyInIframe(subdomain) {78 return loadResourceWithPolicyInIframe(79 _getNELResourceURL(subdomain, "pass.png?id="+reportID+"&success_fraction=0.0"));80}81function clearResourceWithBasicPolicyInIframe(subdomain) {82 return loadResourceWithPolicyInIframe(83 getURLForClearingConfiguration(subdomain));84}85function loadResourceWithPolicyInIframe(url) {86 return new Promise((resolve, reject) => {87 const frame = document.createElement('iframe');88 frame.src = url;89 frame.onload = () => resolve(frame);90 frame.onerror = () => reject('failed to load ' + url);91 document.body.appendChild(frame);92 });93}94/*95 * Fetches a resource whose headers define an include_subdomains NEL policy.96 */97function getURLForResourceWithIncludeSubdomainsPolicy(subdomain) {98 return _getNELResourceURL(subdomain, "subdomains-pass.png?id="+reportID);99}100function fetchResourceWithIncludeSubdomainsPolicy(subdomain) {101 const url = getURLForResourceWithIncludeSubdomainsPolicy(subdomain);102 return fetch(url, {mode: "no-cors"});103}104/*105 * Fetches a resource whose headers do NOT define a NEL policy. This may or may106 * not generate a NEL report, depending on whether you've already successfully107 * requested a resource from the same origin that included a NEL policy.108 */109function getURLForResourceWithNoPolicy(subdomain) {110 return _getNELResourceURL(subdomain, "no-policy-pass.png");111}112function fetchResourceWithNoPolicy(subdomain) {113 const url = getURLForResourceWithNoPolicy(subdomain);114 return fetch(url, {mode: "no-cors"});115}116/*117 * Fetches a resource that doesn't exist. This may or may not generate a NEL118 * report, depending on whether you've already successfully requested a resource119 * from the same origin that included a NEL policy.120 */121function getURLForMissingResource(subdomain) {122 return _getNELResourceURL(subdomain, "nonexistent.png");123}124function fetchMissingResource(subdomain) {125 const url = getURLForMissingResource(subdomain);126 return fetch(url, {mode: "no-cors"});127}128/*129 * Fetches a resource that can be cached without validation.130 */131function getURLForCachedResource(subdomain) {132 return _getNELResourceURL(subdomain, "cached-for-one-minute.png");133}134function fetchCachedResource(subdomain) {135 const url = getURLForCachedResource(subdomain);136 return fetch(url, {mode: "no-cors"});137}138/*139 * Fetches a resource that can be cached but requires validation.140 */141function getURLForValidatedCachedResource(subdomain) {142 return _getNELResourceURL(subdomain, "cached-with-validation.py");143}144function fetchValidatedCachedResource(subdomain) {145 const url = getURLForValidatedCachedResource(subdomain);146 return fetch(url, {mode: "no-cors"});147}148/*149 * Fetches a resource that redirects once before returning a successful150 * response.151 */152function getURLForRedirectedResource(subdomain) {153 return _getNELResourceURL(subdomain, "redirect.py?id="+reportID);154}155function fetchRedirectedResource(subdomain) {156 const url = getURLForRedirectedResource(subdomain);157 return fetch(url, {mode: "no-cors"});158}159/*160 * Fetches resources that clear out any existing Reporting or NEL configurations161 * for all origins that any test case might use.162 */163function getURLForClearingConfiguration(subdomain) {164 return _getNELResourceURL(subdomain, "clear-policy-pass.png?id="+reportID);165}166async function clearReportingAndNELConfigurations(subdomain) {167 await Promise.all([168 fetch(getURLForClearingConfiguration(""), {mode: "no-cors"}),169 fetch(getURLForClearingConfiguration("www"), {mode: "no-cors"}),170 fetch(getURLForClearingConfiguration("www1"), {mode: "no-cors"}),171 fetch(getURLForClearingConfiguration("www2"), {mode: "no-cors"}),172 ]);173 return;174}175async function clearReportingAndNELConfigurationsInIframe(subdomain) {176 await Promise.all([177 clearResourceWithBasicPolicyInIframe(""),178 clearResourceWithBasicPolicyInIframe("www"),...
Using AI Code Generation
1var wpt = new WebPageTest('www.webpagetest.org');2var url = wpt._getNELResourceURL('test.js');3console.log(url);4var wpt = new WebPageTest('www.webpagetest.org');5var url = wpt._getNELResourceURL('test.js');6console.log(url);7var wpt = new WebPageTest('www.webpagetest.org');8var url = wpt._getNELResourceURL('test.js');9console.log(url);10var wpt = new WebPageTest('www.webpagetest.org');11var url = wpt._getNELResourceURL('test.js');12console.log(url);13var wpt = new WebPageTest('www.webpagetest.org');14var url = wpt._getNELResourceURL('test.js');15console.log(url);16var wpt = new WebPageTest('www.webpagetest.org');17var url = wpt._getNELResourceURL('test.js');18console.log(url);19var wpt = new WebPageTest('www.webpagetest.org');20var url = wpt._getNELResourceURL('test.js');21console.log(url);22var wpt = new WebPageTest('www.webpagetest.org');23var url = wpt._getNELResourceURL('test.js');24console.log(url);25var wpt = new WebPageTest('www.webpagetest.org');26var url = wpt._getNELResourceURL('test.js');27console.log(url);28var wpt = new WebPageTest('www.web
Using AI Code Generation
1console.log(url);2console.log(url);3console.log(url);4console.log(url);5console.log(url);6console.log(url);
Using AI Code Generation
1var url = wptb._getNELResourceURL("test.png");2console.log(url);3console.log(url);4console.log(url);5console.log(url);6console.log(url);7console.log(url);8console.log(url);9console.log(url);
Using AI Code Generation
1var url = wptb._getNELResourceURL('test.html');2console.log(url);3var url = wptb._getNELResourceURL('test2.html');4console.log(url);5var url = wptb._getNELResourceURL('test3.html');6console.log(url);7var url = wptb._getNELResourceURL('test4.html');8console.log(url);9var url = wptb._getNELResourceURL('test5.html');10console.log(url);11var url = wptb._getNELResourceURL('test6.html');12console.log(url);13var url = wptb._getNELResourceURL('test7.html');14console.log(url);15var url = wptb._getNELResourceURL('test8.html');16console.log(url);
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!!