browser.alarms is undefined using webextension-polyfill - javascript

I'm trying to create an alarm using browser.alarms API for web extensions.
To make the extension cross-browser, I am using webextension-polyfill and testing on Chrome.
My code to create an alarm within a background script is shown below:
browser.alarms.create('spline-items-notification', {
periodInMinutes: 1
});
However, when I attempt to run this extension, I always get an error:
Uncaught TypeError: Cannot read property 'create' of undefined
I am loading webextension-polyfill before the background script in manifest.json, and other interfaces work, like browser.notifications.
I would like to know how to fix this if possible. Thank you.

alarms
To use this API you need to have the "alarms" permission.
Does the manifest.json have the "alarms" permission?

I think this a bug with webextension-polyfill, but I opened a pull request that should fix it.

Related

Asciidoctor.js Live Preview on Google Chrome

I'm trying to use Asciidoctor.js Live Preview on Google Chrome, but isntead of my doc i see
Error
TypeError : Cannot read property 'join' of null
It also raises an JS error:
Denying load of chrome-extension://iaalpfgpbocpdfblpnhhgllgbdbchmia/js/jquery-2.0.3.min.map.
Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.
Probably i need to add sth to manifest.js file, but I have no idea what.
I cannot figure out how to fix this issue. Any advice would be appreciated.
There's an open issue on Github for this: https://github.com/asciidoctor/asciidoctor-chrome-extension/issues/32
Are you using Windows 8.1 ?
The two JS errors are not related:
Denying load of chrome-extension://iaalpfgpbocpdfblpnhhgllgbdbchmia/js/jquery-2.0.3.min.map.
See jQuery's jquery-1.10.2.min.map is triggering a 404 (Not Found)
Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.
The second one is just the consequence of the first one because jquery-2.0.3.min.map is not declared in the manifest.

Using Google Drive in an iFrame doesn't work

I'm running into some problems using Google Drive in an iFrame. Normally, using it in an iFrame wouldn't be a good idea anyways, but this is for teaching Google Drive, where a student codes up something and then they can preview it.
The preview needs to happen in an iFrame, because that way it's sandboxed, and won't potentially disturb the rest of the page. I've been attempting to do this in a few different ways. I'm thinking it's related to a limitation of using OAuth an iframe, but open to other suggestions.
Here's the non-iframe version which works. This just sets up a Google Picker using my client_id and developer_key. It works fine. http://sandbox.codeschool.com.s3.amazonaws.com/dart/drive.html
Attempt #1
If you try to run this same script in an iframe, things go wrong. Here's an example of this:
http://sandbox.codeschool.com.s3.amazonaws.com/dart/loader-src.html
The entire code for this page is
<iframe height='600' width='800' src='drive.html' sandbox='allow-scripts'></iframe>
Google loader gapi loads, and calls the auth callback correctly, but the script doesn't properly load. This gives this error on this code:
gapi.auth.authorize({
'client_id': clientId,
'scope': ['https://www.googleapis.com/auth/drive']
}, handleAuthentication);
Uncaught TypeError: Cannot call method 'authorize' of undefined
Uncaught TypeError: Cannot read property 'prototype' of undefined
So somehow Google Drive is saying the library loaded, but auth isn't being defined.
Attempt #2
Rather than loading everything in from an iframe via the src, attempting to create an iframe dynamically via JavaScript and write the content in. Here's the link to this example: http://sandbox.codeschool.com.s3.amazonaws.com/dart/loader-js.html Basically something like this:
iframe = document.getElementsByTagName('iframe')[0];
iframe.sandbox = 'allow-scripts';
doc = iframe.contentDocument;
doc.open();
doc.write(htmlContent());
doc.close();
This seems to get us a step farther. Rather than getting the JS error on authorize, the script progresses down to where it creates the picker before failing when it tries to set the developer key.
This gives an error: "The API developer key is invalid.".
I'm initially thinking this is because the browser key referrers are set wrong. Here's what they're set at for this developer key:
http://sandbox.codeschool.com.s3.amazonaws.com/*
http://*
*
Last two were really just to test things. Anyone have any suggestions on possible ways of getting around this restriction?

Uncaught TypeError: Cannot read property 'local' of undefined in chrome extension

I have written a Chrome extension. I cannot use
localStorage.setItem and localStorage.getItem for storing and retrieving because background and browser action runs in different environment [as seen here].
So I decided to use the Chrome storage API:
var storage = chrome.storage.local;
var myTestVar = 'somevar';
var obj = {};
obj[myTestVar] = $("#somevar").val();
storage.set(obj);
which produced the following error:
Uncaught TypeError: Cannot read property 'local' of undefined
What am I doing wrong?
Make sure that all necessary permissions have been declared in the manifest file. "storage", in your case.
In general, the following steps should fix the problem of apparently undefined Chrome APIs:
Read the documentation of the API you're using and get yourself familiar with the prerequisites, usually manifest permissions (e.g. chrome.storage#manifest).
Check if your (user's) Chrome version supports the API, by looking at What's new.
Check if the script is running in the right context. Most APIs are only available to the extension's process. (the chrome.storage API can also be used in content script though)
Otherwise, resort to your usual debugging skills: Typos, variable shadowing, ...
You'll get this error if you try running your app as a simple HTML page opening the HTML file in Chrome.
Add the app in Chrome properly (as an Extension) then run it.

Cordova/Phonegap 1.6 media Example

i dont want to mention that Phonegap has gone sloppy recently...
but I'm trying to use the Media example taken AS IS from their website
using Xcode 4.3..
beside replacing phonegap.js with cordove.js, duh, i got a lot of errors:
ERROR: Method 'create:withDict:' not defined in Plugin 'Media'
FAILED pluginJSON = {"className":"Media","methodName":"create","arguments":["Media1","9476cdcf-7f6c-5e05-a022-fa488e8bed40","http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3"]}
Will use resource 'http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3' from the Internet.
ERROR whitelist rejection: url='http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3'
ERROR whitelist rejection: url='http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3'
ERROR whitelist rejection: url='http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3'
Unable to download audio from: http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3
Failed to initialize AVAudioPlayer: (null)
i just used their example as is, and i'd expect it works...
what should i change? is that a xcode issue maybe??
"whitelist rejection"
Basically, you need to add any external URLs you want to access to the "whitelist" (i.e.: the ExternalHosts key in the Cordova.plist file).
See this answer:
https://stackoverflow.com/a/8045541/878602
...or the PhoneGap Wiki FAQ for iOS:
http://wiki.phonegap.com/w/page/41631150/PhoneGap%20for%20iOS%20FAQ
it looks to me that you can't download the mp3. Can you enter that url in the iphone's safari and download the mp3?
Do you have your own webserver to try maybe? You could see the logs and see if it gets there at all.
BTW I just used the same example yesterday in Android and it works for me.
If you may updating the cordova. They have changed many function names.
For example if you are using the startAudioRecord function in previous versions. Currently they have changed it as startRecord.
Likewise they have changed many internal function names.
Just open your cordova.js. check appropriate function and function name exists.

Uncaught Error: SECURITY_ERR: DOM Exception 18 when I try to set a cookie

I get the following error in Chrome's developer tools window when I try to set a cookie using this jQuery plugin:
Uncaught Error: SECURITY_ERR: DOM Exception 18
What does this error mean and how can I fix it? I get the same error when I use this jQuery plugin.
You're most likely using this on a local file over the file:// URI scheme, which cannot have cookies set. Put it on a local server so you can use http://localhost.
I also had this issue while developping on HTML5 in local.
I had issues with images and getImageData function.
Finally, I discovered one can launch chrome with the --allow-file-access-from-file command switch, that get rid of this protection security.
The only thing is that it makes your browser less safe, and you can't have one chrome instance with the flag on and another without the flag.
You can also "fix" this by replacing the image with its inline Base64 representation:
img.src= "data:image/gif;base64,R0lGODlhCwALAIAAAAAA3pn/ZiH5BAEAAAEALAAAAAALAAsAAAIUhA+hkcuO4lmNVindo7qyrIXiGBYAOw==";
Useful, when you do not intend to publish the page on the web, but instead use it on local machines only.
Faced with the same situation playing with Javascript webworkers. Unfortunately Chrome doesn't allow to access javascript workers stored in a local file.
One kind of workaround below using a local storage is to running Chrome with --allow-file-access-from-files (with s at the end), but only one instance of Chrome is allowed, which is not too convenient for me. For this reason i'm using Chrome Canary, with file access allowed.
BTW in Firefox there is no such an issue.
This error pops up, if you try to create a web worker with data URI scheme.
var w = new Worker('data:text/javascript;charset=utf-8,onmessage%20%3D%20function()%20%7B%20postMessage(%22pong%22)%3B%20%7D'); w.postMessage('ping');
It's not allowed according to the standard: http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#dom-worker
I had this issue when using the history API.
window.history.pushState(null, null, URL);
Even with a local server (localhost), you want to add 'http://' to your URL so that you have something similar to:
http://localhost...
I wasn't completely happy by the --allow-file-access-from-files solution, because I'm using Chrome as my primary browser, and wasn't really happy with this breach I was opening.
Now I'm using Canary ( the chrome beta version ) for my development with the flag on.
And the mere Chrome version for my real blogging : the two browser don't share the flag !
One can also receive this error if using the new (so far webkit only) notification feature before getting permission.
First run:
<!-- Get permission -->
<button onclick="webkitNotifications.requestPermission();">Enable Notifications</button>
Later run:
// Display Notification:
window.webkitNotifications.createNotification('image', 'Title', 'Body').show();
The request permission functions needs to be triggered from an event caused by the user, otherwise it won't be displayed.
I was been getting that error in mobile safari when using ASP.NET MVC to return a FileResult with the overload that returns a file with a different file name than the original. So,
return File(returnFilePath, contentType, fileName);
would give the error in mobile safari, where as
return File(returnFilePath, contentType);
would not.
I don't even remember why I thought what I was doing was a good idea. Trying to be clever I guess.

Categories