How to confirm that file download completed successfully with webextensions? - javascript

downloads.download() would seem to be the easiest function to use for non-interactively dowloading & saving files in a webextension. However, it isn't the most-user friendly function in terms of error-handling. If I understand the documentation correctly, it resolves successfully once a download has started--but that doesn't mean that the download will complete successfully. And it only returns the id of the downloadItem object that has started to download, not a pointer to the object itself, which would seem to be what would be the more useful. (To get the object itself, I have been running downloads.search() queries based on the id. This extra step seems inefficient.)
In my tests, I am finding that even in the simple case of trying to download a file when supplying a url that points to a page-not-found (error 404) address, downloads.download() will happily download "a file" and resolve the promise with no error. The downloadItem's status will show "completed," the file will be shown as "exists," and the error status will be "undefined" (if following the change in the downloadItem's properties using an onChanged listener)--but inspection of the contents of the 4kb file that was generated will indicate that it was all just a 404 error.
My current strategy has been to attempt to download a file, wait for a listener to fire on a change to downloads items' statuses, and check the completion-status and errors properties for the downloadItems. But this all just seems hacky and inefficient. And I still haven't figured out the best way to efficiently detect, for example, 404 errors.
Is there an easier way to safely complete file downloads with webextensions that I am missing, maybe some API that I have overlooked?
(I have been trying to do this in Firefox webextensions, but if it's easier with chrome, I will try it that way instead.)

Related

window.performance.memory is not giving updated data but it should give

I am trying to get memory used by a particular tab in the browser using JavaScript code.
I have tried using window.performance.memory in Chrome. It gives me the JS heap size data but the data returned by it everytime is constant. I am creating new objects in my code (hence, memory usage should increase) but still it returns the same data everytime.
I have also used --enable-precise-memory-info argument to open my Chrome. Still same results.
Is there a way to get updated data from window.performance.memory?
Also is there any other way I can get memory usage data of a particular tab opened in the browser? I want this data to be exported in a text file so that I can use it for further analysis.
(I have tried using Chrome's task manager and Memory Manager extension also. But I want data in a text file.)
Try window.performance.memory after opening chrome in administrator mode.

Websocket saturation in Chrome, blob points to data which does not exist

I've got one of this very difficult to debug problems in my app.
I'm using websockets to receive images from my server. I'm getting around 50 images per second in binary and showing them in a canvas as image.
Everything works ok, but sometimes I'm getting an error:
FileReader error. Name: NotFoundError Message: A requested file or directory could not be found at the time an operation was processed.
My code looks like this:
wsVisualizerManager.onMessage = function(e)
{
if (e.data instanceof Blob)
{
var blob = e.data;
this.reader.readAsArrayBuffer(blob);
}
}
Basically I get a blob and I read it with a FileReader object (this.reader) to be able to visualize it as an image.
As I said everything works, but sometimes, seems that due to receive more images that the ones it can handle I start getting this error.
When I start getting this error I don't get it once, I get it many times, so my app is blocked during a lot of time. If I launch chrome development tools the error stops immediately and my app works again (so maybe this developer tool is cleaning some buffers?).
So, I guess that It is some kind of buffer which get completely full, but the think is that If I have to lose old messages I'm ok with that, but why calling onMessage with a bad formated or inexistent blob?
I don't know exactly how to debug this error, because websocket API has just a few methods and no one allows me to access a buffer or clean it.
A way of generate this error manually (otherwise I get it just twice a day) is putting one breakpoint just at the beginning of onMessage and wait some time. What happens then is that when I press play I start getting this error and after some seconds I start receiving retarded images. So seems that it's not removing the received images or at least not all of them.
I'm developing the server part too. And I'm using C++ with the library websocket++. And my chrome version is: 43.0.2357.125 (64-bit)
Any clue of how to proceed debugging this error or trying to solve the problem?

Finding a strange Javascript function 'window.ueLogError' in a PhantomJS error message

I'm working on a project that involves retrieving multiple websites with PhantomJS and when I try to load Amazon.com, PhantomJS crashes while trying to evaluate this function with the error:
TypeError: 'undefined' is not a function (evaluating 'window.ueLogError')
The weird thing is that I can't seem to find any documentation or explanation of any kind for window.ueLogError. A google search gives a handful of websites with scripts that contain it, but it doesn't seem to be a part of any documentation I can find. Does anyone know anything about ueLogError?
The window object is the global sink in the browser. Every variable that you define globally (e.g. jQuery's $) is a property in window. ueLogError is not some kind of standardized JavaScript function. It is most likely some function for an advertisement script.
Not all resources that a page requests as part of the page load are actually successfully loaded. Some requests fail due to SSL problems. Some requests fail, because the user agent string is not supported. Some requests fail because of unknown reasons.
You can register to the onConsoleMessage, onError, onResourceError, onResourceTimeout events (Example) to see whether there are errors. Usually you will find that some JavaScript file wasn't loaded which would have contained ueLogError which another script depends on.

flashfirebug getting data from actionscript 3 console

My need was to capture data (text data) from flash in a web page.
The data is always changing (wheather data) and this should be exported do a text file so i could manipulate this data.
I tried do this with and my first approach was using a websniffer like fiddler or wireshark.
I used that but could't get data from both because it is embedded in flash.
I used fidler as man-in-midle with wireshark deciphering the data (with the private key from the site cer) but it didn't worked.
After that i tried using flashfirebug pro (the pro allows to run as3 comands in the console). This addon loads the dom tree and refreshes it. After selecting in the page the desired element with inspector (it shows in the left panel the instance and position in the dom) i have acess to the instance properties (and the only one needed is the "html-text" in the right panel).
My problem with this last approach was that it could not communicate with the local file system (if i make "trace(this.text);" in the console it shows the text value but it just shows in the console). The only way to communicate to the file in the hard drive, that i could think of was to throw some error to the log file but could't do that also.
Does anyone have any idea to work with flashfirebug or have some other approach to do this.
Regards,
if you want to work on local filesystems use adobe air.
if you can't, try to work around the browsers sandbox with javascript as bridge to some browser-plugin/-addon which gives you access to local processes and filesystems. to use javascript from flash the ExternalInterface class is your friend.

Accessing memory cache items

I'm writing a Firefox extension and I need to to access items in Firefox's memory cache.
Here is the code I'm working with:
nsICache = Components.interfaces.nsICache
cacheservice = Components.classes["#mozilla.org/network/cache-service;1"].getService(Components.interfaces.nsICacheService);
cachesession = cacheservice.createSession("javascript", nsICache.STORE_IN_MEMORY, false);
cachesession.doomEntriesIfExpired=false;
//fileurl is captured from the nsIObserver and does print out correctly
cachedescriptor = cachesession.openCacheEntry( fileurl, nsICache.ACCESS_READ, false );
ERROR:NS_ERROR_CACHE_KEY_NOT_FOUND here
Since this is data fetched in the background, I have to use an nsIObserver to capture the request and snag it's URI to be used as the cache key.
As I showed above, I get a NS_ERROR_CACHE_KEY not found, though a look through about:cache shows that it clearly is there. I also used a proxy to force caching to disk, but I got the same problem (with the code modified to look at the disk cache). I thought that this might be because the cache item was still being written, so I made a recursive window.setTimeout to continuously call the functions, but even after it is finished downloading I get the same error.
Is this, perhaps, and issue with the nsICacheSession? Maybe I'm not use the correct clientId. If so, what clientId should I be using?
I'm really at a loss here, so I'm hoping you guys can help me out.
Problem was the clientId. I used "javascript" because I saw it in an example. Turns out I needed to use "HTTP" instead.

Categories

Resources