How to use object_url method in wpt

Best JavaScript code snippet using wpt

file_save.js

Source:file_save.js Github

copy

Full Screen

1/* FileSaver.js2 * A saveAs() FileSaver implementation.3 * 1.3.24 * 2016-06-16 18:25:195 *6 * By Eli Grey, http://eligrey.com7 * License: MIT8 * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md9 */10/*global self */11/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */12/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */13var saveAs = saveAs || (function(view) {14 "use strict";15 // IE <10 is explicitly unsupported16 if (typeof view === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {17 return;18 }19 var20 doc = view.document21 // only get URL when necessary in case Blob.js hasn't overridden it yet22 , get_URL = function() {23 return view.URL || view.webkitURL || view;24 }25 , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")26 , can_use_save_link = "download" in save_link27 , click = function(node) {28 var event = new MouseEvent("click");29 node.dispatchEvent(event);30 }31 , is_safari = /constructor/i.test(view.HTMLElement) || view.safari32 , is_chrome_ios =/CriOS\/[\d]+/.test(navigator.userAgent)33 , throw_outside = function(ex) {34 (view.setImmediate || view.setTimeout)(function() {35 throw ex;36 }, 0);37 }38 , force_saveable_type = "application/octet-stream"39 // the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to40 , arbitrary_revoke_timeout = 1000 * 40 // in ms41 , revoke = function(file) {42 var revoker = function() {43 if (typeof file === "string") { // file is an object URL44 get_URL().revokeObjectURL(file);45 } else { // file is a File46 file.remove();47 }48 };49 setTimeout(revoker, arbitrary_revoke_timeout);50 }51 , dispatch = function(filesaver, event_types, event) {52 event_types = [].concat(event_types);53 var i = event_types.length;54 while (i--) {55 var listener = filesaver["on" + event_types[i]];56 if (typeof listener === "function") {57 try {58 listener.call(filesaver, event || filesaver);59 } catch (ex) {60 throw_outside(ex);61 }62 }63 }64 }65 , auto_bom = function(blob) {66 // prepend BOM for UTF-8 XML and text/* types (including HTML)67 // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF68 if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {69 return new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type});70 }71 return blob;72 }73 , FileSaver = function(blob, name, no_auto_bom) {74 if (!no_auto_bom) {75 blob = auto_bom(blob);76 }77 // First try a.download, then web filesystem, then object URLs78 var79 file_saver = this80 , type = blob.type81 , force = type === force_saveable_type82 , object_url83 , dispatch_all = function() {84 dispatch(file_saver, "writestart progress write writeend".split(" "));85 }86 // on any filesys errors revert to saving with object URLs87 , fs_error = function() {88 if ((is_chrome_ios || (force && is_safari)) && view.FileReader) {89 // Safari doesn't allow downloading of blob urls90 var reader = new FileReader();91 reader.onloadend = function() {92 var url = is_chrome_ios ? reader.result : reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');93 var popup = view.open(url, '_blank');94 if(!popup) view.location.href = url;95 url=undefined; // release reference before dispatching96 file_saver.readyState = file_saver.DONE;97 dispatch_all();98 };99 reader.readAsDataURL(blob);100 file_saver.readyState = file_saver.INIT;101 return;102 }103 // don't create more object URLs than needed104 if (!object_url) {105 object_url = get_URL().createObjectURL(blob);106 }107 if (force) {108 view.location.href = object_url;109 } else {110 var opened = view.open(object_url, "_blank");111 if (!opened) {112 // Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html113 view.location.href = object_url;114 }115 }116 file_saver.readyState = file_saver.DONE;117 dispatch_all();118 revoke(object_url);119 }120 ;121 file_saver.readyState = file_saver.INIT;122 if (can_use_save_link) {123 object_url = get_URL().createObjectURL(blob);124 setTimeout(function() {125 save_link.href = object_url;126 save_link.download = name;127 click(save_link);128 dispatch_all();129 revoke(object_url);130 file_saver.readyState = file_saver.DONE;131 });132 return;133 }134 fs_error();135 }136 , FS_proto = FileSaver.prototype137 , saveAs = function(blob, name, no_auto_bom) {138 return new FileSaver(blob, name || blob.name || "download", no_auto_bom);139 }140 ;141 // IE 10+ (native saveAs)142 if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {143 return function(blob, name, no_auto_bom) {144 name = name || blob.name || "download";145 if (!no_auto_bom) {146 blob = auto_bom(blob);147 }148 return navigator.msSaveOrOpenBlob(blob, name);149 };150 }151 FS_proto.abort = function(){};152 FS_proto.readyState = FS_proto.INIT = 0;153 FS_proto.WRITING = 1;154 FS_proto.DONE = 2;155 FS_proto.error =156 FS_proto.onwritestart =157 FS_proto.onprogress =158 FS_proto.onwrite =159 FS_proto.onabort =160 FS_proto.onerror =161 FS_proto.onwriteend =162 null;163 return saveAs;164}(165 typeof self !== "undefined" && self166 || typeof window !== "undefined" && window167 || this.content168));169// `self` is undefined in Firefox for Android content script context170// while `this` is nsIContentFrameMessageManager171// with an attribute `content` that corresponds to the window172if (typeof module !== "undefined" && module.exports) {173 module.exports.saveAs = saveAs;174} else if ((typeof define !== "undefined" && define !== null) && (define.amd !== null)) {175 define("FileSaver.js", function() {176 return saveAs;177 });...

Full Screen

Full Screen

fileSaver.js

Source:fileSaver.js Github

copy

Full Screen

1/* FileSaver.js2 * A saveAs() FileSaver implementation.3 * 1.3.54 * 2018-01-22 15:49:545 *6 * By Eli Grey, https://eligrey.com7 * License: MIT8 * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md9 */1011/*global self */12/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */1314/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/src/FileSaver.js */1516// export default var saveAs = saveAs || (function(view) {17var saveAs = saveAs || (function (view) {18 "use strict";19 // IE <10 is explicitly unsupported20 if (typeof view === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {21 return;22 }23 var24 doc = view.document25 // only get URL when necessary in case Blob.js hasn't overridden it yet26 , get_URL = function() {27 return view.URL || view.webkitURL || view;28 }29 , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")30 , can_use_save_link = "download" in save_link31 , click = function(node) {32 var event = new MouseEvent("click");33 node.dispatchEvent(event);34 }35 , is_safari = /constructor/i.test(view.HTMLElement) || view.safari36 , is_chrome_ios =/CriOS\/[\d]+/.test(navigator.userAgent)37 , throw_outside = function(ex) {38 (view.setImmediate || view.setTimeout)(function() {39 throw ex;40 }, 0);41 }42 , force_saveable_type = "application/octet-stream"43 // the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to44 , arbitrary_revoke_timeout = 1000 * 40 // in ms45 , revoke = function(file) {46 var revoker = function() {47 if (typeof file === "string") { // file is an object URL48 get_URL().revokeObjectURL(file);49 } else { // file is a File50 file.remove();51 }52 };53 setTimeout(revoker, arbitrary_revoke_timeout);54 }55 , dispatch = function(filesaver, event_types, event) {56 event_types = [].concat(event_types);57 var i = event_types.length;58 while (i--) {59 var listener = filesaver["on" + event_types[i]];60 if (typeof listener === "function") {61 try {62 listener.call(filesaver, event || filesaver);63 } catch (ex) {64 throw_outside(ex);65 }66 }67 }68 }69 , auto_bom = function(blob) {70 // prepend BOM for UTF-8 XML and text/* types (including HTML)71 // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF72 if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {73 return new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type});74 }75 return blob;76 }77 , FileSaver = function(blob, name, no_auto_bom) {78 if (!no_auto_bom) {79 blob = auto_bom(blob);80 }81 // First try a.download, then web filesystem, then object URLs82 var83 filesaver = this84 , type = blob.type85 , force = type === force_saveable_type86 , object_url87 , dispatch_all = function() {88 dispatch(filesaver, "writestart progress write writeend".split(" "));89 }90 // on any filesys errors revert to saving with object URLs91 , fs_error = function() {92 if ((is_chrome_ios || (force && is_safari)) && view.FileReader) {93 // Safari doesn't allow downloading of blob urls94 var reader = new FileReader();95 reader.onloadend = function() {96 var url = is_chrome_ios ? reader.result : reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');97 var popup = view.open(url, '_blank');98 if(!popup) view.location.href = url;99 url=undefined; // release reference before dispatching100 filesaver.readyState = filesaver.DONE;101 dispatch_all();102 };103 reader.readAsDataURL(blob);104 filesaver.readyState = filesaver.INIT;105 return;106 }107 // don't create more object URLs than needed108 if (!object_url) {109 object_url = get_URL().createObjectURL(blob);110 }111 if (force) {112 view.location.href = object_url;113 } else {114 var opened = view.open(object_url, "_blank");115 if (!opened) {116 // Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html117 view.location.href = object_url;118 }119 }120 filesaver.readyState = filesaver.DONE;121 dispatch_all();122 revoke(object_url);123 }124 ;125 filesaver.readyState = filesaver.INIT;126127 if (can_use_save_link) {128 object_url = get_URL().createObjectURL(blob);129 setTimeout(function() {130 save_link.href = object_url;131 save_link.download = name;132 click(save_link);133 dispatch_all();134 revoke(object_url);135 filesaver.readyState = filesaver.DONE;136 });137 return;138 }139140 fs_error();141 }142 , FS_proto = FileSaver.prototype143 , saveAs = function(blob, name, no_auto_bom) {144 return new FileSaver(blob, name || blob.name || "download", no_auto_bom);145 }146 ;147 // IE 10+ (native saveAs)148 if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {149 return function(blob, name, no_auto_bom) {150 name = name || blob.name || "download";151152 if (!no_auto_bom) {153 blob = auto_bom(blob);154 }155 return navigator.msSaveOrOpenBlob(blob, name);156 };157 }158159 FS_proto.abort = function(){};160 FS_proto.readyState = FS_proto.INIT = 0;161 FS_proto.WRITING = 1;162 FS_proto.DONE = 2;163164 FS_proto.error =165 FS_proto.onwritestart =166 FS_proto.onprogress =167 FS_proto.onwrite =168 FS_proto.onabort =169 FS_proto.onerror =170 FS_proto.onwriteend =171 null;172173 return saveAs;174}(175 typeof self !== "undefined" && self176 || typeof window !== "undefined" && window177 || this ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org');9 if (err) return console.error(err);10 console.log(data);11});12var wpt = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org');14wpt.getTestResults('140328_1Q_5J', function(err, data) {15 if (err) return console.error(err);16 console.log(data);17});18var wpt = require('webpagetest');19var wpt = new WebPageTest('www.webpagetest.org');20wpt.testStatus('140328_1Q_5J', function(err, data) {21 if (err) return console.error(err);22 console.log(data);23});24var wpt = require('webpagetest');25var wpt = new WebPageTest('www.webpagetest.org');26 if (err) return console.error(err);27 console.log(data);28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31wpt.getTestResultsByLocation('Dulles:Chrome', function(err, data) {32 if (err) return console.error(err);33 console.log(data);34});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('MY_API_KEY');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require("webpagetest");2var wpt = new WebPageTest('www.webpagetest.org', 'A.2e2d7f1c1d1c8c8f9f9f9f9f9f9f9f9f');3 if (err) return console.error(err);4 console.log('Test status:', data.statusText);5 wpt.getTestStatus(data.data.testId, function(err, data) {6 if (err) return console.error(err);7 console.log('Test status:', data.statusText);8 if (data.statusText === 'Test Complete') {9 wpt.getTestResults(data.data.testId, function(err, data) {10 if (err) return console.error(err);11 console.log('Test results:', data);12 });13 }14 });15});16{ [Error: getaddrinfo ENOTFOUND www.webpagetest.org www.webpagetest.org:80] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'www.webpagetest.org', host: 'www.webpagetest.org', port: 80 }17Your name to display (optional):18Your name to display (optional):19Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('A.9b7e8c2f4d7b2c2b4e7a4f4e4d7e8f4d');3api.runTest(url, function(err, data) {4 if (err) return console.error(err);5 console.log('Test status: ' + data.statusText);6 console.log('Test ID: ' + data.data.testId);7 console.log('Test URL: ' + data.data.summary);8 console.log('View the test at ' + data.data.userUrl);9 api.getTestResults(data.data.testId, function(err, data) {10 if (err) return console.error(err);11 console.log('Test results for ' + data.data.url);12 console.log('First view: ' + data.data.median.firstView.loadTime);13 console.log('Repeat view: ' + data.data.median.repeatView.loadTime);14 console.log('View the details at ' + data.data.summary);15 });16});17var wpt = require('webpagetest');18var api = new wpt('A.9b7e8c2f4d7b2c2b4e7a4f4e4d7e8f4d');19api.runTest(url, function(err, data) {20 if (err) return console.error(err);21 console.log('Test status: ' + data.statusText);22 console.log('Test ID: ' + data.data.testId);23 console.log('Test URL: ' + data.data.summary);24 console.log('View the test at ' + data.data.userUrl);25 api.getTestResults(data.data.testId, function(err, data) {26 if (err) return console.error(err);27 console.log('Test results for ' + data.data.url);28 console.log('First view: ' + data.data.median.firstView.loadTime);29 console.log('Repeat view: ' + data.data.median.repeatView.loadTime);30 console.log('View the details at ' + data.data.summary);31 });32});33var wpt = require('webpagetest');

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful