I'm attempting to log all requests made using XmlHttpRequest
in my application.
My application utilises the Tangram library to render WebGL maps. Tangram uses Web Workers to request the data to build the map on seperate threads.
In the head of my HTML page I have the following code:
<!-- Log XMLHttpRequest -->
<script>
(function(open) {
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
console.log(arguments);
return open.call(this, method, url, async, user, pass);
};
})(XMLHttpRequest.prototype.open);
</script>
This successfully logs any requests made in the main thread, but fails to log anything within the Worker threads spun up by Tangram. Is there any way (preferably without modifying any of the Tangram source code) to achieve what I'm trying to do?
Note: My primary interest is in extending the functionality of the XmlHttpRequest
object for use in Web Workers - not necessarily for logging. I've just used logging as an example.
Appreciate any advice/guidance you can provide!
Strainy
You have to run the same code in web worker. The worker is running with completely different global scope. No variables that you set in main thread will have any effect on worker.
I recommend you put that code in file so you can link to it from both main thread and web worker.