I'm trying to follow sample for appAPI.contextMenu in Crossrider API
http://docs.crossrider.com/#!/api/appAPI.contextMenu-method-add
background.js
appAPI.ready(function() {
// Adds a command to all context menus that displays the data object
appAPI.contextMenu.add("key1", "Display data object", function (data) {
console.log('pageUrl: ' + data.pageUrl + '\n' +
'linkUrl: ' + data.linkUrl + '\n' +
'selectedText:' + data.selectedText + '\n' +
'srcUrl:' + data.srcUrl);
}, ["all"]);
// Adds a command to "link" context menus that displays 'Hello World'
// Note: Since both commands display on links, they are grouped in a sub menu
appAPI.contextMenu.add("key2", "Hello World", function (data) {
console.log('Changed onClick to Alert Hello World');
}, ["link"]);
});
extension.js
appAPI.ready(function($) {
});
the following warn is thrown in console log of background page.
Warning: Parameter context value is not supported. Function-name:
appAPI.contextMenu.add
PS, if you are a Crossrider Staff willing to help, a sample can be reproduced by extension id: 62139
The message is a mere warning and does not affect the operation of the extension; hence, it can be safely ignored.
I took the additional precaution of installing the extension on Chrome and Firefox and the context menu works correctly as defined in your code. If you have a specific issue with the extension not working correctly, please feel free to email support#crossrider.com.
[Disclaimer: I am a Crossrider employee]
Related
I have been building small app with Intel XDK. I try to open Phonegap Barcode scanner but when launch button is clicked nothing happens. My goal is to scan a QR code and open inAppBrowser link containing result data. I have both Device (cordova-plugin-device) and Barcode Scanner (phonegap-plugin-barcodescanner) plugins installed with permissions for camera and flash.
Here is my code:
<script type="text/javascript">
document.addEventListener("deviceready", scanNow, false);
function scanNow() {
cordova.plugins.barcodeScanner.scan(
function (result) {
// alert("We got a barcode\n" +
// "Result: " + result.text + "\n" +
// "Format: " + result.format + "\n" +
// "Cancelled: " + result.cancelled);
window.open("http://www.example.com?qr=" + result.text, '_system', 'location=no');
},
function (error) {
alert("Error: " + error);
});}
</script>
And this is the launch button:
<a role='button' onclick="scanNow();">Scan</a>
EDIT: I solved the problem by adding this link to a dummy script to my index page head.
<script src="cordova.js"></script>
You don't need to call your scanNow() function on the deviceready event, you just need to insure that calls to it do not happen until after the deviceready event has fired. Since you're debugging, I would change that line to something like...
document.addEventListener("deviceready", alertDeviceReady, false);
...and add an alertDeviceReady() that gives you an alert or console message. Usually it takes a second or two, but can take longer on slow devices or if you've got some plugins that require a long init time.
This is going to be a security problem...
window.open("http://www.example.com?qr=" + result.text, '_system', 'location=no');
...because you should not open the webview to another page (you're navigating away from the built-in webview that your app is running inside of, you're not associated with a website).
You can use inAppBrowser to open an alternate view on top of the webview, but I advise that you use the explictly named inAppBrowser APIs and do not assume that it has been aliased to use window.open() -- because they have deprecated that usage and, I believe, it is not aliased in the default installation anymore. That is, try using...
cordova.inAppBrowser.open()
...instead.
See the docs here which will also include details regarding the current release for that plugin (which may only work with CLI 5+ builds) and contains a link to the github repo for more information.
I've been trying to generate a PDF using the wkhtmltopdf tool (http://wkhtmltopdf.org/). The page from which I want to generate a PDF using jQuery and has some initializations using a jQuery.ready() function, something like this:
jQuery(function() {
// do something
});
However, when I try to generate a PDF from the page the script is not executed. I've tried setting a delay to wait for the JavaScript to be executed with the option:
--javascript-delay 30000
But the result is the same.
When I've enabled wkhtmltopdf's JavaScript debugging option I get a warning, which I'm not sure if it's related to the problem:
Warning: undefined:0 TypeError: 'null' is not an object
Has anyone encountered this problem? Is there some kind of workaround?
EDIT: Seems the problem is caused by the error Warning: undefined:0 TypeError: 'null' is not an object. I've managed to print the error on the PDF using:
window.onerror = function(error, url, line) {
$('body').before('<b> Error: ' + error + '</b> <br />');
$('body').before('<b> Url: ' + url + '</b> <br />');
$('body').before('<b> Line: ' + line + '</b> <br />');
console.log(error, ' ', url, ' ', line);
};
But the information is very limited and I have no idea what might cause it:
Error: TypeError: 'null' is not an object
Url: undefined
Line: 0
The problem turned out to be that Qt doesn't support localStorage, so one of the initialization scripts failed which cause the jQuery.ready() not being executed.
I've managed to debug it with a browser with Qt support: QtWeb. (Tried Arora as well, couldn't run it on my system).
I tried this code:
var contextMenu = require("context-menu");
var menuItem = contextMenu.Item({
label: "Test name",
contentScript: 'self.on("click", function () {' +
' window.open("options.html", "_blank");' +
'});'
});
But when I click on the new Context menu item, I get the following error:
Security Error: Content at "le Site" may not load or link to chrome://browser/content/options.html.
Which permissions do I have to give of get?
It seems that the relative address is resolved incorrectly in case of a content script - as a result you are attempting to open chrome://browser/content/options.html in a window which is correctly forbidden. Simply specify the full address and things should work:
' window.open("http://example.com/options.html", "_blank");' +
I've decided that there are some errors which I don't want to go to the browser error handler. But I still want to know about them. In my actual code I have a function which stores the errors in a hidden element and ajax submits them to a database. Following is a simplified version of my try block:
try
{
newValueEvaled = eval(newValue);
}catch(err)
{
alert("Error caught: Line " + err.lineNumber + ((err.columnNumber != undefined)?', Column:' + err.columnNumber:"") + '\n' + err.message);
}
I'd like the columnNumber too. Currently it is never there, but somehow the browser error console has access to it. Can anyone tell me how I can get access to it as well?
I'm almost certain it's not possible to get the error column number from JavaScript running in the page. Firebug/WebKit console/IE console has access to internal browser objects that provide more information about the call stack than is available to code running inside the page.
You can access the error line and possibly column using a custom error handler function:
function dumpErrors(error, file, line, column)
{
alert('Error: ' + error + ', occurred in file: ' + file + ', on line: ' + line + ', at column: ' + (column || 'unknown'));
}
onerror = dumpErrors;
The «line» is available for all browsers. For the «column», it seems it's available on latest Chrome (release 30.0+), but not on Firefox (release 17, running on my Linux).
I have a page on which mysterious JavaScript errors keep popping up. They appear to be coming from the application we use and do not own the source for. I'm working on a real solution to this issue, but we have a demo tomorrow and I was wondering if there is a way to just suppress JS errors page wide (like wrapping ALL the javascript components in a giant try catch).
You could add a handler to the window.onerror event. In this case, all the errors that occur inside the window will be redirected to the handler of this event. (I did test this in Firefox and it worked, but I was having trouble with it in Chrome - my Chrome installation is pretty messed up, so that could be the problem, but there are Chromium bugs filed that relate to this issue: bug #7771 and bug #8939)
window.onerror = function (msg, url, line) {
alert("Error on line " + line + " in " + url + ":\n" + msg);
// return true to prevent browser from displaying error
return true;
}