Chrome V3 synchronous notification before request - google-chrome-extension

I have to add a header whose value is derived from the content of a file. I've solved the problem polling the file for changes and calling declarativeNetRequest.updateDynamicRules each time the file changes. The only way to avoid this polling is being synchronously notified each time a request is going to happen. I've not found a way to do this with this API. Does it exist?

Related

Play a sound when download is ready

The user selects some options then clicks "download". At that point, my php script starts preparing the file, and it can take 5-10 minutes before the file is ready and starts downloading. I want to notify the user with a sound that the download has started.
How can I do that?
According to this question:
Is there a way to detect the start of a download in JavaScript?
There is no programmatic way to detect when a download begins. That question is six years old now, so perhaps it is out of date, but I could not find any more recent information to contradict it.
An alternative approach would be to break the download process into two parts so that you can control when the actual data transfer begins:
Instead of initiating the download immediately, have the button send an AJAX request to the server asking it to prepare the file for download.
The server should not reply to the AJAX immediately, but should prepare the file and save it in a temporary file storage area with a unique generated name/ID.
Once the file is ready, the server should reply to the AJAX with the name/ID of the file.
On the client, the AJAX completion callback can play the sound, since it knows the download is about to begin.
It then uses window.open() to request the file from the server.
Now the server can respond with the appropriate headers as you used to do.
Finally, the server can delete the file from temporary storage (or just wait for a cron job to do it).

Prevent post request timeout

I'm making a POST request to a nodejs server that contains just a file name in the body. Upon receiving the request, node uploads the corresponding local file to an Amazon S3 bucket. The files can sometimes take awhile to upload, and sometimes the request times out. How can I lengthen or prevent the timeout from happening?
You can send the response back to the browser while you still continue to work on the upload. You don't have to wait until the upload is done before finishing the response. For example, you can do:
res.end("done"); // or put whatever HTML you want in the response
And, that will end the post response and the browser will be happy. Meanwhile, your server continues to finish the upload.
The upside to this is that the browser and user goes on their merry way to the next thing they want to do without waiting for the server to finish its business. The only downside I'm aware of is that if the upload fails, you don't have a simple means of informing the browser that it failed (because the response is already done).
The timeout itself is controlled by the browser. It is not something that you can directly control from the server. If you are continually sending data to the browser, then it will likely not timeout. So, as long as the upload was continuing, you could do something like this:
res.write(" ");
every 15 seconds or so as sort of a keep-alive that keeps the browser happy and keeps it from timing out. You'd probably set an interval timer for 15 seconds to do the small send of data and then when the upload finishes you would stop the timer.
If you control the Javascript in the browser that makes the post, then you can set the timeout value on an Ajax call from the Javascript in the browser. When you create an XMLHttpRequest object in the browser, it has a property called timeout which you can set for asynchronous ajax calls. See MDN for more info.

Modifying content delivered by node-http-proxy

Due to some limitations about the web services I am proxying, I have to inject some JS code so that it allows the iframe to access the parent window and perform some actions.
I have built a proxy system with node-http-proxy which works pretty nicely. However I have spent unmeasurable hours trying to modify the content (on my own, using harmon as well, etc) that is being sent to the user without any success. I have found some articles and even some questions here but all of them are outdated and are not useful anymore.
I was wondering if someone can give me an actual example about how to do this, because I am unable to do it and maybe it is just that it is impossible to do at this point?
I haven't tried harmon, but I did try cheerio and it works.
However, I used http-mitm-proxy and not node-http-proxy.
If you are using http-mitm-proxy, you need to return a promise in the response handler. Otherwise, the proxy continues to send the original response without picking up your changes.
I have recently written another proxy at:
https://github.com/noeltimothy/noelsproxy
I'm going to add response handling to this soon. This one uses a callback mechanism, which means it wont return the response until the caller signals it to.
You should be able to use 'cheerio' and alter the content in JQuery style.

Trouble making a request to an API after the last 'session/end'

I'm currently working on a custom reporter that sends test results to Sauce Labs. The current version of the reporter can be found here.
The problem with it is that it doesn't send the data after the last session. For instance, if I have 2 browsers to test on, it will only send the results for the first browser tested, stopping before sending the second one.
The request is made at the 'session/end' topic from the ones available. From what I can tell the entire thing stops before the last request is made.
I made a more isolated custom reporter to show off the problem using setTimeout() instead of a request. See it here.
Thanks!
The Intern process exits explicitly immediately after all sessions are complete (after /runner/end is published), so an asynchronous operation like that is unlikely to have enough time to complete successfully.
Intern 1.2 will contain an improvement so it will wait until any outstanding operations complete, and this will work as you expect it to.

Is there a way to run custom code on Azure Cache expiration? (where last cached value is accessible)

What I mean is a kind of event or callback which is called when some cached value is expiring. Supposedly this callback should be given the currenlty cached value, for example, to store it somewhere else apart from caching.
To find such a way, I have reviewed Notifications option, but they look like they are applicable for explicit actions with cache like adding or removing, whereas expiration is a kind of thing that occurs implicitly. I found out that none of these callbacks is not called many minutes after cache value has expired and has become null, while it is called normally within polling interval if I call DataCache.Remove explicitly (wrong, see update below).
I find this behavior strange as ASP.Net has such callback. You can even find an explanation how to utilize it here on SO.
Also, I tried DataCache Events. It is writtent in MSDN that literally
This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.
Nevertheless I created a handler for these event to see if I can test its args like CacheOperationStartedEventArgs.OperationType == CacheOperationType.ClearCache but it seemed to be in vain.
At the moment, I started to think about workarounds of this issue of the lack of required callback. So suggestions how to implement them are welcome too.
UPDATE. After more attentive and patient testing I found out that notification with DataCacheOperations.ReplaceItem is sent after expiration. Regrettably, I did not find the way to get the value that was cached before the expiration had occurred.

Resources