JS Files not included in the Package created through CFX tool - firefox

I am developing a Firefox Add-On through CFX tool but while i am using cfx.xpi the Addon xpi is not having other Javascripts files which i am using as a thread ( using Worker ).
I am using :
var twrite = new Worker("t_write.js");
t_write.js is my worker file. But while executing it like this it is giving an Error: Malformed script URI:t_write.js
Please help me by letting me know how to include those files in the add-on package and what is this Malformed Scipt Error

Related

How to reference script files in webpack deploy?

I am using webpack and electron and while I can reference my script files fine locally (app/scripts/scriptname.sh), when it comes to the production deploy, I get an error: Can't open app/components/scripts/scriptname.sh.
It's unclear to me if this is an electron-dependent issue or a webpack-issue.
I am running these using node child_process as:
var ls = spawn('sh', ['app/components/scripts/scriptname.sh']);
I don't necessarily need the scripts to be in their own folder it would just be helpful.
You need to provide the complete absolute path to the script. To do that you can use the app.getAppPath() API of electron
app.getAppPath()
Returns String - The current application directory.
So your code would be something like:
var scriptAbsolutePath = app.getAppPath() + '/app/components/scripts/scriptname.sh';
var ls = spawn('sh', [scriptAbsolutePath]);
You can also have a look at app.getPath(name) API if it satisfies your particular requirement.

How to create a xpi file from scratchpad

I have developed my add-on in scratchpad environment and now developing is finished and I want to create final xpi file.
I replace only this:
Cu.import('resource://gre/modules/ctypes.jsm');
by this:
var {Cu} = require("chrome");
var{ctypes} = Cu.import("resource://gre/modules/ctypes.jsm", null);
Then using nodejs (jpm init and jpm xpi commands) I created xpi file however this is not worked properly.
What we did was follow the jpm tutorial: https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Getting_Started_%28jpm%29 and https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/jpm#Installation
I did this on a Windows system:
we downloaded node.js
npm came with it
created a directory, in this directory i did jpm-init from command line
filled out the prompts then filled in the code for the addon:
We then created a similiar addon to this demo addon here:
https://github.com/Noitidart/jpm-chromeworker
I cant share the actuall addon as that was personal to the user. But the above is simpler and shows how to do it.
We did our jsctypes in a chromeworker, and have it communicate with index.js via messaging

Parse CLI won't upload non-js files

I'm trying to send iOS push notifications using my Cloud Code (I can't use Parse's Push APIs as my app is built using ionic and all their docs expect native).
I have it working as a standalone script locally using nodejs, but when I go to upload it to parse, I get:
Uploading source files
Note that the following files will not be uploaded:
parse_cloud_code/cloud/cloud/cert.pem
parse_cloud_code/cloud/cloud/key.pem
Uploading recent changes to scripts...
The following files will be uploaded:
parse_cloud_code/cloud/cloud/cloud.js
parse_cloud_code/cloud/cloud/cloud_test.js
parse_cloud_code/cloud/cloud/credentials.js
parse_cloud_code/cloud/cloud/fs.js
parse_cloud_code/cloud/cloud/push-notification.js
parse_cloud_code/cloud/cloud/push-notifications_test.js
parse_cloud_code/cloud/cloud/tls.js
Finished uploading files
Error: Failed to load cloud/cert.pem with: Could not find file cloud/cert.pem
at Object.exports.readFile (cloud/fs.js:24:17)
at readFile (cloud/push-notification.js:45:8)
at body (cloud/push-notification.js:56:5)
at cloud/push-notification.js:147:3
at cloud/push-notification.js:156:3
at cloud/cloud.js:5073:5
at cloud/cloud.js:5082:3
at main.js:1:13
How can I get the .pem files into the cloud code? I tried renaming them to .js but then Parse wanted them to actually be syntactically JS files. Imagine that.
I found a workaround for this situation, as I had a similar problem. Any non-js file that I must upload I would rename to .ejs. So the parse CLI will upload it and them you can use it inside your cloud code.

Deploying custom resource through DSC PullServer fails to extract the module

I've set up a DSC PullServer on Server 2008 R2 and I've run into an issue deploying a custom module. The module on the PullServer is in C:\Program Files\WindowsPowerShell\Modules\NTFSPermission, I've zipped everything using Windows Explorer (and 7-zip) and placed the zip in C:\Program Files\WindowsPowerShell\DscService\Modules\NTFSPermission_1.0.zip, I create a checksum using NEW-DSCChecksum for the zip file and I've got Import-DSCResource NTFSPermission in my node configuration. When I run the Invoke-CimMethod to push the config to a node it errors out with:
Invoke-CimMethod : Failed to extract the module from zip file
C:\Windows\TEMP\\635291179507191263\NTFSPermission_1.0.zip downloaded by Download
Manager WebDownloadManager.
The node logs a 4104 error in the event viewer reading:
This event indicates that failure happens when LCM is trying to get the configuration from pull server using download manager WebDownloadManager. ErrorId is 0x1. ErrorDetail is Failed to extract the module from zip file C:\Windows\TEMP\\635291179507191263\NTFSPermission_1.0.zip downloaded by Download Manager WebDownloadManager.
Has anyone else run into this? I'm not sure if there's a config file somewhere that is literally piping in an extra backslash and causing an invalid download/extraction path or if there is something wrong with the zipped module. If I move the module over manually the config will be pushed and apply successfully, which leads me to believe it's not the module.
There is a known issue with extracting zip files created using .NET compression class in 4.5. The workaround is to use the shell method of compressing files. That is, send to compressed archive option in right-click context menu or using Shell COM object.
I tested one of the modules from the DSC Resource Kit and it extracted with no problems on the desired node. I tracked the problem down to the psd file that the author created for their DSC-Resource. I updated the CLRVersion to require 4.0 and removed RequiredModules, RequiredAssemblies, ScriptsToProcess, TypesToProcess,FormatsToProcess and NestedModules (all were empty values anyway), pushed the config without the workaround and it downloaded and extracted the resource.

Use relative path in Firefox extension

I develop Firefox extension with bundled executable file which should be run on browser startup.
To run process I need get nsIFile or nsILocalFile instance which points to executable file.
I know one solution how to get it using directory service:
var file = Components.classes["#mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
file.append("extensions");
file.append("<extension id>");
file.append("<relative path>");
But this solution has two disadvantages:
It doesn't work in development mode, when instead of installed extension I have only text file with real extension path
I'm not sure that it will work on all Firefox configurations because of hardcoded "extensions" part of the path
So is there any nicer way to run executable file which comes with Firefox extension?
Thanks.
You are making way too many assumptions about the directory structure of the Firefox profile - don't. The Add-on Manager API lets you get the path of a file inside the extension, you should use it:
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID("<extension id>", function(addon)
{
var uri = addon.getResourceURI("<relative path>");
var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file;
...
});
A restartless addon's startup function (in the bootstrap.js file) will receive, as its first parameter, the path where the addon is installed. You can then play various tricks to read files inside the .jar file, if any: see https://github.com/protz/GMail-Conversation-View/blob/master/bootstrap.js#L55 as an example.
In a non-restartless case, I must confess I don't have much of an idea :).
I found this thread looking for a way to reference a path to an image hosted in extension's directory from a content script. Here's a solution:
Include your files in web_accessible_resources in the extension's manifest.
"web_accessible_resources": [
"images/*"
]
Absolute paths to these resources contain randomly generated UUID, therefore we're using runtime.getUrl() giving it the path relative to manifest.json. Example:
let myImg = document.createElement('img');
myImg.src = browser.runtime.getURL("images/my-img.png")

Resources