Chrome extension API: chrome.experimental.clear.* not working? - caching

I made a simple extension that contains a button, that when clicked, executes the following code:
chrome.experimental.clear.cache('everything', function() {
});
but the callback function never seems to get called. Am I using this API wrong or is it just broken?
Here's a link to the API doc for it:
http://code.google.com/chrome/extensions/experimental.clear.html#method-cache
Thanks!

The API has changed to chrome.experimental.browsingData.
I've just landed the documentation updates to go along with the code change: http://code.google.com/chrome/extensions/trunk/experimental.browsingData.html

Here's the most up to date documentation (chrome.browsingData.removeCache):
http://developer.chrome.com/trunk/extensions/browsingData.html#method-removeCache

Related

Firefox web-extension api captureVisibleTab refturns undefined

I have been trying to create a Firefox add-on using the web extensions API. My add-on should take a screenshot of the current page the user is browsing using chrome.tabs.captureVisibleTab but it returns undefined. They say that its already implemented in the API on http://arewewebextensionsyet.com/ but I can't seem to get it to work.
Here is my code:
chrome.tabs.captureVisibleTab(null, {}, function(data) {
console.log("screenshotData: " + data);
});
I have also tried passing in a window.id as the first parameter even though in the docs it says its optional, but this also returns an undefined value for data.
Does anyone have any experience with this in particular?
It works for me in Nightly 49.0a1 (2016-06-04).
Make sure you have the following permission in your manifest.json file:
"permissions": [ "<all_urls>" ]

Modernizr.videoautoplay object shows true, Modernizr.videoautoplay returning undefined

I'm using a custom Modernizr build, v3.3.0. I've created a simple JSFiddle example to illustrate: https://jsfiddle.net/cqkg7x45/6/.
console.log(Modernizr);
will show the Modernizr object, and when I inspect it in the JS console I can see "videoautoplay" is a property with a value of "true".
But, when I do
console.log(Modernizr.videoautoplay)
it returns "undefined".
I was originally seeing this issue in a WordPress theme I'm developing, but was also able to recreate in JSFiddle and a separate stand-alone HTML page. Also, Modernizr is putting the "videoautoplay" class on my HTML tag, even when I know the device does not support that feature (iPhone 5).
Update: This issue appears to be happening in Chrome (v47.0.2526.106), but not Firefox (v43.0.2).
I'm going to answer my own question in case anyone else runs into this problem. I found the solution on this SO post: How do I detect if the HTML5 autoplay attribute is supported?.
Since this is an "async" test you can't access the property using the syntax
Modernizr.videoautoplay
You have to use the .on() function, as shown in the above SO post:
Modernizr.on('videoautoplay', function(result){
if(result) {
alert('video autoplay is supported');
} else {
alert('video autplay is NOT supported');
}
});

Plain JS Ajax Upload Progress Event Not Working

I am trying to use object-oriented code to handle an AJAX upload. When I run the code, it sees the file, creates the XMLHttpRequest object, but I cannot seem to get the progress event to fire. The full source of my code can be found here: http://pastebin.com/89QawbS6
Here is a snippet:
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", MyObj.trackProgress, false);
xhr.open("POST", url, true);
...
Then in that same object, different method:
trackProgress: function (event) {
console.log(event);
// stuff that should calculate percent
}
But that console.log(event) never fires.
Please note: I know jQuery is great, and there are a dozen awesome upload plugins that I could just use instead. I am not doing this for a class or homework, I just want to understand the process better myself. So offering a jQuery plugin as an answer is not what I'm looking for. I'm trying to make myself less dependent on jQuery.
This FF bug might be the reason for your issue. It's reported on MacOSX and another similar bug on Linux. I don't know if that matters but I tested on Windows. I still believe that your code is fine.

Use onAuthPrompt() with CasperJS and SlimerJS

SlimerJS added a onAuthPrompt callback. Is it possible to get it to work with CasperJS?
I found mention that the phantomjs or slimerjs object is available as casper.page, and then the following answer said that casper.page is only available after calling casper.start(): https://stackoverflow.com/a/16629231/841830
So I tried this code. The onAuthPrompt code is taken from the documentation; I just added a log line to make sure it works.
casper.test.begin("first",function suite(test){
casper.start();
casper.page.onAuthPrompt = function (type, url, realm, credentials) {
console.log("onAuthPrompt: type="+type+",url="+url+",realm="+realm+",credentials="+credentials); //TEMP
credentials.username = "laurent";
credentials.password = "1234";
return true;
};
casper.thenOpen(url,function(){
console.log('Loaded:'+url);
test.assertSelectorHasText('#msg','');
this.capture('1.png');
});
casper.run(function(){test.done();});
});
It loads url (which does not require auth), then an XMLHttpRequest or EventSource connection is made, which is what requires authentication. I see the password prompt pop-up but my onAuthPrompt() function is not getting called.
Am I doing something wrong, or is this not what onAuthPrompt is for, or could it be a bug that I could report (but in that case, do you think the problem is in CasperJS or in SlimerJS?).
According to the documentation, the onAuthPrompt callback was added in version 0.9.0, which has yet to be released.
You can check the documentation from the master branch of the Git repo here.
There is also the latest released documentation (v0.8.3) here

What's the correct way to listen for a Google+ Hangout state change?

The Hangout API at https://developers.google.com/+/hangouts/writing includes an example to set a callback function when the hangout state has changed, like this:
gapi.hangout.onStateChanged.add(onStateChange);
When run, this results in an error similar to "gapi.hangout.onStateChanged is undefined". A quick check in Firebug shows that the onStateChanged method belongs to gapi.hangout.data not gapi.hangout.
What is the correct way to add a callback function when the state has changed?
The method that you're looking for is indeed a member of gapi.hangout.data. The writing article you mention seems to be out of date. I fix it :)
To do something when state changes just attach a callback:
gapi.hangout.data.onStateChanged.add(function() {
console.log(gapi.hangout.data.getState());
});
You can find working examples of the code in action on the sample apps page.

Resources