Socket
Socket
Sign inDemoInstall

firefox-profile

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firefox-profile - npm Package Compare versions

Comparing version 0.2.12 to 0.3.0

4

CHANGELOG.md

@@ -0,1 +1,5 @@

# 0.2.13
* normalize extension path (thanks @halo2376)
# 0.2.12

@@ -2,0 +6,0 @@

50

doc/firefox_profile.md

@@ -1,2 +0,2 @@

Constructor
Firefox Profile

@@ -7,4 +7,5 @@ _Source: [lib/firefox_profile.js](../lib/firefox_profile.js)_

- <a name="toc_firefoxprofilecopyprofiledirectory"></a><a name="toc_firefoxprofile"></a>[FirefoxProfile.copy](#firefoxprofilecopyprofiledirectory)
- <a name="toc_firefoxprofileprototypedeletedir"></a><a name="toc_firefoxprofileprototype"></a>[FirefoxProfile.prototype.deleteDir](#firefoxprofileprototypedeletedir)
- <a name="toc_firefoxprofileoptions"></a>[FirefoxProfile](#firefoxprofileoptions)
- <a name="toc_firefoxprofilecopyoptions"></a>[FirefoxProfile.copy](#firefoxprofilecopyoptions)
- <a name="toc_firefoxprofileprototypedeletedira"></a><a name="toc_firefoxprofileprototype"></a>[FirefoxProfile.prototype.deleteDir](#firefoxprofileprototypedeletedira)
- <a name="toc_firefoxprofileprototype_cleanonexit"></a>[FirefoxProfile.prototype._cleanOnExit](#firefoxprofileprototype_cleanonexit)

@@ -27,13 +28,30 @@ - <a name="toc_firefoxprofileprototypeshoulddeleteonexittrue"></a>[FirefoxProfile.prototype.shouldDeleteOnExit](#firefoxprofileprototypeshoulddeleteonexittrue)

<a name="firefoxprofile"></a>
# FirefoxProfile(options)
# FirefoxProfile.copy(profileDirectory)
> Initialize a new instance of a Firefox Profile.
> creates a profile Profile from an existing firefox profile directory
*
Note that this function uses filesystem sync functions to copy an existing profile (id profileDirectory is provided)
which is not optimized.
If you need optimzed async version, use `FirefoxProfile.copy(profileDirectory, cb);`
**Parameters:**
- `{String | null} profileDirectory` optional. if provided, it will copy the directory synchronously
- `{Object | String | null} options` optional. if it is an object, it can contain the following option: * profileDirectory: the profile to copy. Not recommended: use [FirefoxProfile.copy](#firefoxprofilecopyoptions) instead
* destinationDirectory: where the profile will be stored. If not provided,
a tmp direcoty will be used WARNING: if it will be emptied!!
if it is a string it will copy the directory synchronously.
(not recommended at all, kept for backward compatibility)
<sub>Go: [TOC](#tableofcontents)</sub>
# FirefoxProfile.copy(options)
> creates a profile Profile from an existing firefox profile directory asynchronously
**Parameters:**
- `{Object | String | null} options` if it is an object: * profileDirectory - required - the profile to copy.
* destinationDirectory: where the profile will be stored. If not provided,
a tmp direcoty will be used. WARNING: if it will be emptied!!
<sub>Go: [TOC](#tableofcontents) | [FirefoxProfile](#toc_firefoxprofile)</sub>

@@ -43,3 +61,3 @@

# FirefoxProfile.prototype.deleteDir()
# FirefoxProfile.prototype.deleteDir(a)

@@ -49,9 +67,7 @@ > Deletes the profile directory asynchronously.

Call it only if you do not need the profile. Otherwise use at your own risk.
this function is automatically called by default (= if willDeleteOnExit() returns true)
@param cb a callback function with boolean parameter (false if the dir is not found)
```js
that will be called when the profileDir is deleted
```
**Parameters:**
- `{cb} a` callback function with boolean parameter (false if the dir is not found) that will be called when the profileDir is deleted
<sub>Go: [TOC](#tableofcontents) | [FirefoxProfile.prototype](#toc_firefoxprofileprototype)</sub>

@@ -63,2 +79,4 @@

this function is automatically called by default (= if willDeleteOnExit() returns true) if a tmp directory is used
should not be called directly. process.on('exit') cannot be asynchronous: async code is not called

@@ -97,3 +115,3 @@

Any modification to the user preference can be persisted using this.updatePreferences()
If this.setPreference() is called before calling this.encoded(), then this.updatePreferences()
If this.setPreference() is called before calling this.encoded(), then this.updatePreferences()
is automatically called.

@@ -139,3 +157,3 @@ For a comprehensive list of preference keys, see http://kb.mozillazine.org/About:config_entries

updatePreferences() is automatically called when encoded() is called
updatePreferences() is automatically called when encoded() is called
(if needed = if setPreference() was called before calling encoded())

@@ -142,0 +160,0 @@

@@ -33,3 +33,3 @@ module.exports = function(grunt) {

options: {
files: ['test/*.js', 'test/**/*.js']
files: ['test/*.js', 'test/**/*.js', '!test/extensions/**/*.js']
}

@@ -36,0 +36,0 @@

@@ -0,1 +1,4 @@

/**
* Firefox Profile
*/
'use strict';

@@ -81,18 +84,30 @@

function parseOptions(opts) {
if (_.isString(opts)) {
return {profileDirectory: opts};
}
return opts || {};
}
/**
* Constructor
* Initialize a new instance of a Firefox Profile.
*
* Initialize a new instance of a Firefox Profile
* Note that this function uses filesystem sync functions to copy an existing profile (id profileDirectory is provided)
* which is not optimized.
* If you need optimzed async version, use `FirefoxProfile.copy(profileDirectory, cb);
* If you need optimzed async version, use `FirefoxProfile.copy(profileDirectory, cb);`
*
* @param {String|null} profileDirectory optional. if provided, it will copy the directory synchronously (not recommended)
* @param {Object|String|null} options optional. if it is an object, it can contain the following option:
* * profileDirectory: the profile to copy. Not recommended: use FirefoxProfile.copy instead
* * destinationDirectory: where the profile will be stored. If not provided,
* a tmp direcoty will be used WARNING: if it will be emptied!!
* if it is a string it will copy the directory synchronously.
* (not recommended at all, kept for backward compatibility)
*/
function FirefoxProfile(profileDirectory) {
function FirefoxProfile(options) {
var opts = parseOptions(options),
hasDestDir = !!opts.destinationDirectory;
this.profileDir = opts.profileDirectory;
this.defaultPreferences = _.clone(config.DEFAULT_PREFERENCES);
this.profileDir = profileDirectory;
// if true, the profile folder is deleted after
this._deleteOnExit = true;
this._deleteOnExit = !hasDestDir;
// can be turned to false when debugging

@@ -102,9 +117,10 @@ this._deleteZippedProfile = true;

if (!this.profileDir) {
this.profileDir = this._createTempFolder();
this.profileDir = opts.destinationDirectory || this._createTempFolder();
} else {
// create copy
var tmpDir = this._createTempFolder('-copy');
wrench.copyDirSyncRecursive(profileDirectory, tmpDir, {
var tmpDir = opts.destinationDirectory || this._createTempFolder('-copy');
wrench.copyDirSyncRecursive(opts.profileDirectory, tmpDir, {
forceDelete: true,
filter: /^(parent\.lock|lock|\.parentlock)$/ // excludes parent.lock, lock, .parentlock not copied
preserveFiles: hasDestDir,
filter: /^(parent\.lock|lock|\.parentlock)$/ // excludes parent.lock, lock, .parentlock
});

@@ -126,7 +142,7 @@ this.profileDir = tmpDir;

});
}
};
function deleteParallel(files, cb) {
async.parallel(files.map(function(file) {
return function(next) { fs.unlink(file, next)};
return function(next) { fs.unlink(file, next); };
}), function () {

@@ -137,2 +153,3 @@ cb && cb();

FirefoxProfile.prototype._copy = function(profileDirectory, cb) {

@@ -142,4 +159,4 @@ var self = this;

forceDelete: true,
preserveFiles: true,
filter: /^(parent\.lock|lock|\.parentlock)$/ // does not work, not implemented in wrench (async version)
preserveFiles: true
// filter: /^(parent\.lock|lock|\.parentlock)$/ // does not work, not implemented in wrench (async version)
}, function() {

@@ -154,10 +171,17 @@ // remove parent.lock, lock or .parentlock files if they have been copied

/**
* creates a profile Profile from an existing firefox profile directory
* *
* @param {String|null} profileDirectory optional. if provided, it will copy the directory synchronously
* creates a profile Profile from an existing firefox profile directory asynchronously
*
* @param {Object|String|null} options if it is an object:
* * profileDirectory - required - the profile to copy.
* * destinationDirectory: where the profile will be stored. If not provided,
* a tmp direcoty will be used. WARNING: if it will be emptied!!
*/
FirefoxProfile.copy = function(profileDirectory, cb) {
var profile = new FirefoxProfile();
profile._copy(profileDirectory, function() {
FirefoxProfile.copy = function(options, cb) {
var opts = parseOptions(options);
if (!opts.profileDirectory) {
throw new Error('firefoxProfile: .copy() requires destinationDirectory');
}
var profile = new FirefoxProfile({destinationDirectory: opts.destinationDirectory});
profile._copy(opts.profileDirectory, function() {
cb && cb(profile);

@@ -171,6 +195,5 @@ });

* Call it only if you do not need the profile. Otherwise use at your own risk.
* this function is automatically called by default (= if willDeleteOnExit() returns true)
@param cb a callback function with boolean parameter (false if the dir is not found)
that will be called when the profileDir is deleted
*
* @param cb a callback function with boolean parameter (false if the dir is not found)
* that will be called when the profileDir is deleted
*/

@@ -197,2 +220,4 @@ FirefoxProfile.prototype.deleteDir = function(cb) {

*
* this function is automatically called by default (= if willDeleteOnExit() returns true) if a tmp directory is used
*
* should not be called directly. process.on('exit') cannot be asynchronous: async code is not called

@@ -202,3 +227,3 @@ *

FirefoxProfile.prototype._cleanOnExit = function() {
if (fs.existsSync(this.profileDir)) {

@@ -237,5 +262,5 @@ try {

* Set a user preference.
*
*
* Any modification to the user preference can be persisted using this.updatePreferences()
* If this.setPreference() is called before calling this.encoded(), then this.updatePreferences()
* If this.setPreference() is called before calling this.encoded(), then this.updatePreferences()
* is automatically called.

@@ -285,3 +310,3 @@ * For a comprehensive list of preference keys, see http://kb.mozillazine.org/About:config_entries

return function(callback) {
self.addExtension(extension, callback);
self.addExtension(path.normalize(extension), callback);
};

@@ -296,6 +321,6 @@ });

* Save user preferences to the user.js profile file.
*
* updatePreferences() is automatically called when encoded() is called
*
* updatePreferences() is automatically called when encoded() is called
* (if needed = if setPreference() was called before calling encoded())
*
*
*/

@@ -493,3 +518,3 @@ FirefoxProfile.prototype.updatePreferences = function() {

self = this;
if (addon.slice(-4) === '.xpi') {

@@ -538,3 +563,3 @@ tmpDir = this._createTempFolder(addon.split(path.sep).slice(-1));

});
});

@@ -662,2 +687,2 @@

module.exports = FirefoxProfile;
{
"name": "firefox-profile",
"version": "0.2.12",
"version": "0.3.0",
"description": "firefox profile for selenium WebDriverJs, admc/wd or any other node selenium driver that supports capabilities",

@@ -50,2 +50,7 @@ "main": "lib/firefox_profile",

}
,
{
"name": "halo2376",
"url": "https://github.com/halo2376"
}
],

@@ -52,0 +57,0 @@ "devDependencies": {

@@ -99,3 +99,5 @@ # firefox-profile-js

fp.setPreference('extensions.firebug.defaultPanelName', 'console');
// done with prefs?
fp.updatePreferences();
// you can install multiple extensions at the same time

@@ -116,2 +118,4 @@ fp.addExtensions(['./test/extensions/firebug-1.12.4-fx.xpi'], function() {

You can also copy an existing profile... Check the doc `FirefoxProfile.copy(...)`.
## API Documentation

@@ -118,0 +122,0 @@

/*jshint camelcase:false*/
/*global describe:false, it:false, beforeEach:false, afterEach:false*/
/*global describe:false, it:false, before, beforeEach:false, afterEach:false*/

@@ -27,2 +27,7 @@ 'use strict';

before(function() {
if (!fs.existsSync(testProfiles.dest)) {
fs.mkdirSync(testProfiles.dest);
}
});
afterEach(function(done) {

@@ -41,3 +46,3 @@ // will remove the onexit() call (that deletes the dir folder)

it('with parameter, lock files should not be copied over', function() {
it('with string parameter, lock files should not be copied over', function() {
var fp = new FirefoxProfile(testProfiles.emptyProfile.path);

@@ -52,2 +57,14 @@ expect(fp.profileDir.slice(-5)).to.be.equal('-copy');

it('should copy the profile into destinationDirectory if specified', function() {
var fp = new FirefoxProfile({ profileDirectory: testProfiles.emptyProfile.path,
destinationDirectory: testProfiles.dest
});
expect(fp.profileDir).to.be.equal(testProfiles.dest);
expect(fs.statSync(fp.profileDir).isDirectory()).to.be.true;
['.parentlock', 'lock', 'parent.lock'].forEach(function(lockFile) {
expect(fs.existsSync(path.join(fp.profileDir, lockFile))).to.be.false;
});
expect(fs.existsSync(path.join(fp.profileDir, 'empty.file'))).to.be.true;
});
});

@@ -67,2 +84,16 @@ describe('#Firefox.copy', function() {

it('should copy the profile into destinationDirectory if specified', function(done) {
FirefoxProfile.copy({ profileDirectory: testProfiles.emptyProfile.path,
destinationDirectory: testProfiles.dest
}, function(fp) {
expect(fp.profileDir).to.be.equal(testProfiles.dest);
expect(fs.statSync(fp.profileDir).isDirectory()).to.be.true;
['.parentlock', 'lock', 'parent.lock'].forEach(function(lockFile) {
expect(fs.existsSync(path.join(fp.profileDir, lockFile))).to.be.false;
});
expect(fs.existsSync(path.join(fp.profileDir, 'empty.file'))).to.be.true;
done();
});
});
});

@@ -69,0 +100,0 @@

var path = require('path');
module.exports = {
dest: path.join(__dirname, 'dest-dir'),
brandNewProfile: {

@@ -5,0 +6,0 @@ expectedZip: 'UEsFBgAAAAAAAAAAAAAAAAAAAAAAAA=='

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc