firefox bootstrap addon: install event is not executed - javascript

I'm trying to create a bootstrapped addon that just sets the new tab url at install to a new value and resets it to the old one when it gets uninstalled.
Here is my bootstrap.js. I think the install function throws an exception because require is not defined, but I'm not sure if the debugger executes the code I write in Scratchpad in the right scope.
I read somewhere that the api is the same for bootstrapped extensions as the with the add-on sdk, so the require should be fine. If this is not the case, could you please direct me to a page that describes the code I can use in the bootstrap.js, I didn't find anything :(
function startup(data, reason){
}
function shutdown(data, reason){
}
function install(data, reason){
var prev_new_tab_url = require("sdk/preferences/service").get("browser.newtab.url");
var data = require("sdk/self").data;
var url = data.url("startpage.html");
require("sdk/preferences/service").set("browser.newtab.url", url);
var ss = require("sdk/simple-storage");
ss.storage.prev_new_tab_url = prev_new_tab_url;
}
function uninstall(data, reason){
var ss = require("sdk/simple-storage");
var prev_new_tab_url = ss.storage.prev_new_tab_url;
require("sdk/preferences/service").set("browser.newtab.url", prev_new_tab_url);
}

from: https://forums.mozilla.org/viewtopic.php?f=7&t=22621&sid=4ea13ebd794f85600d6dcbcf6cc590a7
in bootstrap you dont have access to sdk stuff like that. im not sure how to access that stuff.
but i made exactly what you are looking for with localization :D took like 10min :D
https://github.com/NoitForks/l10n/tree/setpref-install-uninstall
note: the quirk that localization files are not available during the uninstall procedure. so i had to move this to shutodwn proc while testing for aReason of ADDON_DISABLE. it makes sense that files are not available in uninstall
you asked:
How do you know the Services.prefs.getCharPref method?
i responded:
I first imported the Services.jsm module then i looked on MDN for what all it had:
https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Services.jsm?redirectlocale=en-US&redirectslug=JavaScript_code_modules%2FServices.jsm
then i saw prefs then it linked to nsIPrefBranch and that documented all of it. nsIPrefBranch2 is deprecated so I knew it wasn't that.
MDN is your friend :)

Plain bootstrapped add-ons do not automatically get access to the SDK, i.e. there is no require.
Either use non-SDK stuff exclusively, like nsIPrefBranch, Services.jsm, etc.
Or write an SDK add-on in the first place
Or hook up the SDK loader for your add-on yourself. Only instance I know other than SDK add-ons themselves (heh) that does such a thing is Scriptish.

Related

Adobe Sign JS SDK

Adobe changed their GitHub from the last time we imported their latest code for the JS SDK. It used to have pre-generated Browser specific JS files that you copy paste into the code, now it uses Swagger auto generation into Node.Js files and wants the users to browserify it to use it in browser js.
TL:DR I don't know how to convert the node.js files into browser files
I have tried following all of the instructions that they have in their readme, but nothing seems to work. The only thing I haven't tried (which could be the key) is to write my code in a JS file with the node.js "require()" to import the js files, then browserify my code. If that's what I have to do then I unfortunately will not be able to upgrade.
Right now the code that I use to access the api is this
<!-- supplied by Adobe before -->
<script type="text/javascript" src="~/scripts/sha1-min.js"></script>
<script type="text/javascript" src="~/scripts/adobe-sign-sdk.js"></script>
<script type="text/javascript" src="~/scripts/superagent.min.js"></script>
<script type="text/javascript" src="~/scripts/validator.min.js"><</script>
async function GenerateAuthForm() {
var context = new AdobeSignSdk.Context();
//Initialize the Widget API
var agreementApi = new AdobeSignSdk.AgreementsApi(context);
//Get the Widget model
var widgetsModel = AdobeSignSdk.AgreementsModel;
var agreementsModel = AdobeSignSdk.AgreementsModel;
//Populate the access token
/**/
var agreementCreationInfo = new agreementsModel.DocumentCreationInfo();
//does more work below
and that is super easy to call and use.
I want to be able to do that same process, but with the updated version, so I can use Workflows rather than agreements.
EDIT:
I have tried to browserify the index.js located at /AdobeSignNodeJsSdk/src and it did combine all of the files, but I had no way to call it, or I didn't understand how to call it. I tried to call it as below
<script src="~/Scripts/bundle.js"></script>
<script>
var context = new SwaggerJsClient.ApiClient(); //this was undefined
var api = new context.WorkflowsApi()
//do stuff with the api or model
Furthermore in the file that was put through browserify, it references root.SwaggerJsClient.apiormethod, so I assumed that there is some way to call this, and I just don't know what it is.
I am closing this question as I figured out how to import the code properly using browserify like this
browserify -r ./index.js:AdobeSignSdk > bundle.js
then referencing it like
var adobeSignSdk = require('AdobeSignSdk');
var context = new adobeSignSdk.ApiClient();
And I would like to report that the "Latest version" after going through the code and determining how to use it, has significantly LESS functionality than the previous version. You cannot create a Workflow through 2.0, you can only get the existing ones, and their statuses. The previous release, 1.1.0 still doesn't work correctly when you try to create a workflow as they didn't include
customWorkflowAgreementCreationRequest.getDocumentCreationInfo()
so when you try to create one it fails with an error.
TypeError: customWorkflowAgreementCreationRequest.getDocumentCreationInfo is not a function
This is unfortunate as that is the feature I needed, and I will likely now have to switch my application from JS to the C# REST Api, something that needed to happen anyways, just waiting for when it wasn't so urgent.

Check if analytics.js is loaded

I have to use a local analytics.js that I serve from my server. I just want to use the local version if necessary - so is there a solution for checking if the call for analytics.js has failed?
I thought about checking it with a global window.onerror, but I don't think a failed call for an external file causes an error. I've tried checking if ga() is available, but it is even if analytics.js isn't loaded.
Any ideas? If you are wondering, not all users of this site has internet access, that's why I'm serving a local version. There is more things happening in this case, like adding a sendHitTask to redirect the answer from analytics.js to the local server.
EDIT
A solution where you check if the user has Internet access would also be OK. But I have not found any solution for this either that works on all modern browsers.
There's a function to track if the library has loaded. From the docs:
ga(function(tracker) {
var defaultPage = tracker.get('page');
});
The passed in function is executed when the library is loaded, so you could set a variable to keep track of whether or not it has loaded. You'd have to put it on some sort of timer to decide when you want to consider it failed:
var loaded = false;
ga(function() {
loaded = true;
});
// after one second do something if the library hasn't loaded
setTimeout(function(){
if (!loaded){
//do something
}
},1000);
instead of waiting for a callback, you can easily get it with
if(window.ga && ga.loaded) {
// yeps... it is loaded!
}
you can easily see this in the Firefox documentation
same trick can be applied if you want to see if the tracker is blocked (by any plugin for example)
if(window.ga && ga.q) {
// yeps... blocked! >:o
}
A particularly elegant solution would be to use RequireJS and leverage its support for fallback paths. I do this on my site to load a stub version of analytics.js if loading GA fails because the visitor uses a privacy tool blocking the request:
http://veithen.github.io/2015/02/14/requirejs-google-analytics.html
Your use case is similar, except that you want to fallback to a complete local copy. You also probably don't want to change all calls to GA as described in that article. If that's the case then you could use a hybrid approach where you only use RequireJS to load analytics.js (Google's version or the local copy), without changing any other code.
Setting this up would involve the following steps:
Add RequireJS to your site and configure it as follows:
require.config({
paths: {
"ga": [
"//www.google-analytics.com/analytics",
"local-copy-of-analytics"
]
}
});
Use the alternative version of the tracking code, but replace <script async src='//www.google-analytics.com/analytics.js'></script> with the following JavaScript code:
require(["ga"]);

Eclipse HTML5 Project - JavaScript Code Assist Only Works In Certain Cases

I am using Eclipse Juno developing a static web project. My project uses several different JavaScript files. One of the files contains a function:
function IconData(size, url) {
this.size = size;
this.url = url;
}
I have another function that returns an object of type IconData:
function PageInfo() {
this.iconData = function() {
var iconData = new IconData();
iconData.size = 10;
iconData.url = "http://somepage.com/image.png";
return iconData;
}
}
In another JavaScript file I create an instance of PageInfo and call the function iconData:
var page = new PageInfo();
// populate stuff
var icon = page.iconData();
If I type icon. then CTRL+SPACE to start code assist I get the following message popups in Eclipse:
No Default Proposals
No Template Proposals
However, if I create a new instance of icon data such as:
var iconData = new IconData();
then I type iconData. then CTRL-SPACE the code assist pops up and show me all the possibilities:
My question is, why doesn't code assist work in the first scenario but it works in the second?
Thank you.
P.S. I have Google how to enable code assist for JavaScript in Eclipse I found several sites that said I need to make sure I have JavaScript Development Tools installed and I made sure that I have them installed so I know that is not the issue.
I think it's a limitation with JSDT. I suggest you that you install tern.java which extends JSDT to improve JS completion, hyperlink, hover.
Copy your JS files in a folder, convert your project as tern and configure Script path with your folder. Please read Getting Started to know how to do that.
Here a screenshot with your case (here scripts folder is configured as script path):
Please note that tern.java is developed with Eclipse Luna, so I suggest you to use this version and not Juno.

why my firefox add-on cannot do Request

My addon is working fine without bugs, But If add the bellow code in my addon script Main.js then my extension will not work at all.
Why?
What I should do ?
var Request = require("sdk/request").Request;
var quijote = Request({
url: "http://www.latin1files.org/",
onComplete: function (response) {
console.log(response.text);
}
});
quijote.get();
Addon:
https://addons.cdn.mozilla.net/_files/478037/proxylist-initial.rev19-fx.xpi
So the addon is not working if I want to use Request or Timer. How to resolve this ?
I think the problem is in settings files, maybe in bootstrap.js or harness-options.json, or somewhere where it must be initialized, but i don't know much about firefox addon sdk. I know that above code must work, but i need to include or to declare something that will allow me to use Request.
That must be declared in harness-options.json
There is no request.js file in your /resources/addon-sdk/lib/sdk/ folder. As you can see in the comments to the announcement of SDK 1.15, bundling the SDK modules with the extension is no longer necessary (since FF21).

Common Controls Replacement Project - How to get started?

I want to use the Common Controls Replacement Project in my Windows Scripting Host (WSH) HTML Application (HTA). In particular the Extended File Dialogs DLL.
How do I get started?
In my JavaScript I have:
var fso = new ActiveXObject('Scripting.FileSystemObject'), WshShell = new ActiveXObject('WScript.Shell'), OpenDialog = new ActiveXObject('ccrpFileDialog')
The first two work OK, but on the third I get an error, "Automation server can't create object." I have already registered "ccrpFD6.dll" using regsvr32.
I don't see any newbie FAQs or discussion groups, so I don't know who else to turn to.
Are there better documented alternatives I can use instead?
Thanks!!
As far as I can tell, it doesn't work that way. It looks like these controls are only intended to be used from VB 5/6 projects, not from VBScript or HTAs.
I registered the DLL version which puts a "ccrpFD_DLL6.ccrpFileDialogDLL" ProgId in the registry.
Calling it with set fd = WScript.CreateObject("ccrpFD_DLL6.ccrpFileDialogDLL") produced "H:\projects\ccrpFileDialogTest.vbs(5, 1) ccrpFD_DLL6: Invalid procedure call or argument"
I then registered the OCX version which created a ProgId of "ccrFileDialogs6.ccrpFileDialogs".
Calling this in a similar way produced this error: "H:\projects\ccrpFileDialogTest.vbs(6, 1) WScript.CreateObject: Could not locate automation class named "ccrpFileDialogs"."

Categories

Resources