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.0.2 to 0.0.3

.travis.yml

55

doc/firefox_profile.md

@@ -8,4 +8,5 @@ /

- <a name="toc_firefoxprofileprototypesetpreferencethe-"></a><a name="toc_firefoxprofileprototype"></a><a name="toc_firefoxprofile"></a>[FirefoxProfile.prototype.setPreference](#firefoxprofileprototypesetpreferencethe-)
- <a name="toc_firefoxprofileprototypeaddextensionpath-the"></a>[FirefoxProfile.prototype.addExtension](#firefoxprofileprototypeaddextensionpath-the)
- <a name="toc_firefoxprofileprofiledirectory"></a>[FirefoxProfile](#firefoxprofileprofiledirectory)
- <a name="toc_firefoxprofileprototypesetpreferencekey-value"></a><a name="toc_firefoxprofileprototype"></a>[FirefoxProfile.prototype.setPreference](#firefoxprofileprototypesetpreferencekey-value)
- <a name="toc_firefoxprofileprototypeaddextensionpath-callback"></a>[FirefoxProfile.prototype.addExtension](#firefoxprofileprototypeaddextensionpath-callback)
- <a name="toc_firefoxprofileprototypeupdatepreferences"></a>[FirefoxProfile.prototype.updatePreferences](#firefoxprofileprototypeupdatepreferences)

@@ -18,12 +19,20 @@ - <a name="toc_firefoxprofileprototypepath"></a>[FirefoxProfile.prototype.path](#firefoxprofileprototypepath)

- <a name="toc_firefoxprofileprototypenativeeventsenabled"></a>[FirefoxProfile.prototype.nativeEventsEnabled](#firefoxprofileprototypenativeeventsenabled)
- <a name="toc_firefoxprofileprototypesetnativeeventsenabledtrue"></a>[FirefoxProfile.prototype.setNativeEventsEnabled](#firefoxprofileprototypesetnativeeventsenabledtrue)
- <a name="toc_firefoxprofileprototypeencoded"></a>[FirefoxProfile.prototype.encoded](#firefoxprofileprototypeencoded)
- <a name="toc_firefoxprofileprototypesetproxya"></a>[FirefoxProfile.prototype.setProxy](#firefoxprofileprototypesetproxya)
- <a name="toc_firefoxprofileprototypesetnativeeventsenabledboolean"></a>[FirefoxProfile.prototype.setNativeEventsEnabled](#firefoxprofileprototypesetnativeeventsenabledboolean)
- <a name="toc_firefoxprofileprototypeencodedfunction"></a>[FirefoxProfile.prototype.encoded](#firefoxprofileprototypeencodedfunction)
- <a name="toc_firefoxprofileprototypesetproxyobject"></a>[FirefoxProfile.prototype.setProxy](#firefoxprofileprototypesetproxyobject)
# FirefoxProfile(profileDirectory)
> Initialize a new instance of a Firefox Profile
**Parameters:**
- `{String | null} profileDirectory` optional. if provided, it will copy the directory
<sub>Go: [TOC](#tableofcontents)</sub>
<a name="firefoxprofileprototype"></a>
<a name="firefoxprofile"></a>
# FirefoxProfile.prototype.setPreference(key, value)
# FirefoxProfile.prototype.setPreference(the, )
> Set a user preference.

@@ -36,12 +45,14 @@

- `{string} the` user preference key
- `{boolean | string} `
- `{string} key` - the user preference key
- `{boolean | string} value`
**See:**
- [](http://kb.mozillazine.org/About:config_entries)
- [about:config](http://kb.mozillazine.org/About:config_entries)
<sub>Go: [TOC](#tableofcontents) | [FirefoxProfile.prototype](#toc_firefoxprofileprototype)</sub>
# FirefoxProfile.prototype.addExtension(path, the)
# FirefoxProfile.prototype.addExtension(path, callback)

@@ -52,4 +63,4 @@ > Add an extension to the profile.

- `{string} path` to a xpi extension file or a unziped extension folder
- `{function} the` callback function to call when the extension is added
- `{string} path` - path to a xpi extension file or a unziped extension folder
- `{function} callback` - the callback function to call when the extension is added

@@ -66,3 +77,3 @@ <sub>Go: [TOC](#tableofcontents) | [FirefoxProfile.prototype](#toc_firefoxprofileprototype)</sub>

> @return {string} path the the profile extension directory
> @return {string} path of the profile extension directory

@@ -109,3 +120,3 @@ <sub>Go: [TOC](#tableofcontents) | [FirefoxProfile.prototype](#toc_firefoxprofileprototype)</sub>

# FirefoxProfile.prototype.setNativeEventsEnabled(true)
# FirefoxProfile.prototype.setNativeEventsEnabled(boolean)

@@ -116,7 +127,7 @@ > If not explicitly set, default: true

- `{boolean} true` to enable native events.
- `{boolean} boolean` true to enable native events.
<sub>Go: [TOC](#tableofcontents) | [FirefoxProfile.prototype](#toc_firefoxprofileprototype)</sub>
# FirefoxProfile.prototype.encoded()
# FirefoxProfile.prototype.encoded(function)

@@ -126,9 +137,9 @@ > return zipped, base64 encoded string of the profile directory

**Return:**
**Parameters:**
`{string}`
- `{Function} function` a callback function with first params as a zipped, base64 encoded string of the profile directory
<sub>Go: [TOC](#tableofcontents) | [FirefoxProfile.prototype](#toc_firefoxprofileprototype)</sub>
# FirefoxProfile.prototype.setProxy(a)
# FirefoxProfile.prototype.setProxy(object)

@@ -142,3 +153,3 @@ > set network proxy settings.

- `{Object} a` proxy object. Mandatary attribute: proxyType
- `{Object} object` a proxy object. Mandatary attribute: proxyType

@@ -145,0 +156,0 @@ <sub>Go: [TOC](#tableofcontents) | [FirefoxProfile.prototype](#toc_firefoxprofileprototype)</sub>

96

lib/firefox_profile.js

@@ -11,3 +11,5 @@ /**/

wrench = require('wrench'),
AdmZip = require('adm-zip');
AdmZip = require('adm-zip'),
archiver = require('archiver'),
uuid = require('node-uuid');

@@ -74,9 +76,17 @@ var config = {

function unprefix(root, node, prefix) {
return root[prefix + ':' + node] || root[node];
}
/**
* Initialize a new instance of a Firefox Profile
*
* @param {string|undefined} path to folder contains the firefox profile
* @return {FrefoxProfile} a new instance of FirefoxProfile
* @param {String} profileDirectory
*/
var FirefoxProfile = function(profileDirectory) {
/**
* Initialize a new instance of a Firefox Profile
*
* @param {String|null} profileDirectory optional. if provided, it will copy the directory
*/
function FirefoxProfile(profileDirectory) {
this.defaultPreferences = config.DEFAULT_PREFERENCES;

@@ -87,7 +97,14 @@ this.profileDir = profileDirectory;

} else {
throw 'not implemented yet!';
// create copy
var tmpDir = this._createTempFolder('-copy');
wrench.copyDirSyncRecursive(profileDirectory, tmpDir, {
forceDelete: true,
filter: /^(parent\.lock|lock|\.parentlock)$/ // excludes parent.lock, lock, .parentlock not copied
});
this.profileDir = tmpDir;
//throw 'not implemented yet!';
}
this.extensionsDir = path.join(this.profileDir, 'extensions');
this.userPrefs = path.join(this.profileDir, 'user.js');
};
}

@@ -100,6 +117,6 @@ /**

*
* @param {string} the user preference key
* @param {boolean|string}
* @param {string} key - the user preference key
* @param {boolean|string} value
* @see http://kb.mozillazine.org/About:config_entries
* @see about:config http://kb.mozillazine.org/About:config_entries
*/

@@ -113,3 +130,3 @@ FirefoxProfile.prototype.setPreference = function(key, value) {

} else if (typeof(value) === 'string') {
cleanValue = '"' + value + '"';
cleanValue = '"' + value.replace('\n', '\\n') + '"';
} else {

@@ -124,4 +141,4 @@ cleanValue = parseInt(value, 10).toString();

*
* @param {string} path to a xpi extension file or a unziped extension folder
* @param {function} the callback function to call when the extension is added
* @param {string} path - path to a xpi extension file or a unziped extension folder
* @param {function} callback - the callback function to call when the extension is added
*/

@@ -141,3 +158,3 @@ FirefoxProfile.prototype.addExtension = function(extension, cb) {

/**
* @return {string} path the the profile extension directory
* @return {string} path of the profile extension directory
*

@@ -196,3 +213,3 @@ */

*
* @param {boolean} true to enable native events.
* @param {boolean} boolean true to enable native events.
*

@@ -208,12 +225,27 @@ */

*
* @return {string}
* @param {Function} function a callback function with first params as a zipped, base64 encoded string of the profile directory
*/
FirefoxProfile.prototype.encoded = function() {
var zip = new AdmZip();
zip.addLocalFolder(this.profileDir);
var res = zip.toBuffer().toString('base64');
return res;
FirefoxProfile.prototype.encoded = function(cb) {
var self = this,
tmpFolder = this._createTempFolder(),
files = wrench.readdirSyncRecursive(this.profileDir),
zipStream = fs.createWriteStream(path.join(tmpFolder,'profile.zip')),
archive = archiver('zip', { forceUTC: true });
zipStream.on('close', function() {
cb(fs.readFileSync(path.join(tmpFolder,'profile.zip')).toString('base64'));
});
archive.pipe(zipStream);
files.forEach(function(filePath) {
console.log('file in profile: ', filePath);
if (fs.statSync(path.join(self.profileDir, filePath)).isFile()) {
archive.append(fs.createReadStream(path.join(self.profileDir, filePath)), { name: filePath });
}
});
archive.finalize();
};
// only one found in proxy.js
// only '1' found in proxy.js
var ffValues = {

@@ -232,3 +264,3 @@ 'direct': 1,

*
* @param {Object} a proxy object. Mandatary attribute: proxyType
* @param {Object} object a proxy object. Mandatary attribute: proxyType
*/

@@ -261,3 +293,3 @@ FirefoxProfile.prototype.setProxy = function(proxy) {

});
fs.writeFileSync(this.userPrefs, content, {flag: 'w+'});
fs.writeFileSync(this.userPrefs, content); // defaults to utf8 (node 0.8 compat)
};

@@ -346,5 +378,7 @@

var em = getNamespaceId(doc, "http://www.mozilla.org/2004/em-rdf#"),
rdf = getNamespaceId(doc, "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
rdf = getNamespaceId(doc, "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
// first description
var description = doc[rdf + ':RDF'][rdf + ':Description'];
var rdfNode = unprefix(doc, 'RDF', rdf);
var description = unprefix(rdfNode, 'Description', rdf);
if (description && description[0]) {

@@ -359,6 +393,13 @@ description = description[0];

});
Object.keys(description).forEach(function(attr) {
if (details[attr.replace(em + ':', '')] !== undefined) {
details[attr.replace(em + ':', '')] = description[attr][0];
}
});
cb && cb(details);
});
};

@@ -368,3 +409,3 @@

suffix = suffix || '';
var folderName = path.join(os.tmpDir(), crypto.randomBytes(6).toJSON().join('-') + suffix + '/');
var folderName = path.join(os.tmpDir(), uuid.v4() + suffix + '/');
fs.mkdirSync(folderName);

@@ -399,2 +440,1 @@ //console.log('created folder: ', folderName);

module.exports = FirefoxProfile;
{
"name": "firefox-profile",
"version": "0.0.2",
"version": "0.0.3",
"description": "firefox profile for selenium WebDriverJs",

@@ -31,3 +31,10 @@ "main": "lib/firefox_profile",

"chai": "~1.8.0",
"sinon": "~1.7.3"
"sinon": "~1.7.3",
"sinon-chai": "~2.4.0",
"chai-fs": "0.0.3",
"grunt": "~0.4.1",
"grunt-mocha-test": "~0.7.0",
"blanket": "~1.1.5",
"grunt-contrib-watch": "~0.5.3",
"grunt-apidox": "~0.1.3"
},

@@ -37,4 +44,6 @@ "dependencies": {

"adm-zip": "~0.4.3",
"xml2js": "~0.2.8"
"xml2js": "~0.2.8",
"node-uuid": "~1.4.1",
"archiver": "~0.4.10"
}
}
# firefox-profile-js
[![Build Status](https://travis-ci.org/saadtazi/firefox-profile-js.png)](https://travis-ci.org/saadtazi/firefox-profile-js)
Firefox Profile for [Selenium WebdriverJS](https://code.google.com/p/selenium/wiki/WebDriverJs)

@@ -46,15 +48,19 @@

// attach your newly created profile
capabilities.set('firefox_profile', myProfile.encoded());
myProfile.encoded(function(prof) {
capabilities.set('firefox_profile', myProfile.encoded());
myProfile.setPreference('browser.newtab.url', 'http://saadtazi.com');
// required to create or update user.js
myProfile.updatePreferences();
// start the browser
var wd = new webdriver.Builder().
withCapabilities(capabilities).
build();
// woot!
wd.get('http://en.wikipedia.org');
});
myProfile.setPreference('browser.newtab.url', 'http://saadtazi.com');
// required to create or update user.js
myProfile.updatePreferences();
// start the browser
var wd = new webdriver.Builder().
withCapabilities(capabilities).
build();
// woot!
wd.get('http://en.wikipedia.org');
});

@@ -66,12 +72,25 @@

It can be regenerated using ``apidox --input lib/firefox_profile.js --output doc/firefox_profile.md``.
Requires [apidox](https://github.com/codeactual/apidox).
It can be regenerated using ``grunt docs``.
Requires [apidox](https://github.com/codeactual/apidox) - listed in devDependencies.
## Tests
mocha
# or
grunt mochaTest:test
## Coverage
grunt mochaTest:coverage
Generates doc/coverage.html
## TODO
* add documentation and comments
* write tests
* fix bugs
* ~~add documentation and comments~~
* ~~write tests~~
* ~~fix bugs~~
* write more tests
* fix more bugs
* clean tmp directory on process 'exit' and 'SIGINT'

@@ -82,5 +101,9 @@ ## Disclaimer

I currently only use the addExtension(), I only quickly manually tested the user preference and it now seems to work.
I currently only use the addExtension(), ~~I only quickly manually tested the user preference~~ I am in the process of ading more tests.
f.setPreference('browser.newtab.url', 'http://saadtazi.com');
f.updatePreferences();
## Found a bug?
Open a [github issue](https://github.com/saadtazi/firefox-profile-js/issues).
/*jshint camelcase:false*/
/*global describe:false, it:false*/
/*global describe:false, it:false, beforeEach:false*/
'use strict';
var expect = require('chai').expect,
var chai = require('chai'),
path = require('path'),
expect = chai.expect,
// sinon = require('sinon'),
FirefoxProfile = require('../lib/firefox_profile'),
fs = require('fs');
chai.use(require('sinon-chai'));
chai.use(require('chai-fs'));
describe('firefox_profile', function() {

@@ -16,3 +22,70 @@ describe('#constructor', function() {

});
it('with parameter, lock files should not be copied over', function() {
var fp = new FirefoxProfile(path.join(__dirname, 'empty-profile'));
expect(fp.profileDir.slice(-6)).to.be.equal('-copy/');
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;
});
});
describe('#setPreference', function() {
describe('should correctly store string values', function() {
it('without newline characters', function () {
var fp = new FirefoxProfile();
fp.setPreference('test.string.value', 'test string value');
expect(fp.defaultPreferences).to.have.property('test.string.value', '"test string value"');
});
it('with newline characters', function () {
var fp = new FirefoxProfile();
fp.setPreference('test.string.value', 'test string\n value');
expect(fp.defaultPreferences).to.have.property('test.string.value', '"test string\\n value"');
});
});
it('should correctly store boolean values', function () {
var fp = new FirefoxProfile();
fp.setPreference('test.true.boolean', true);
fp.setPreference('test.false.boolean', false);
expect(fp.defaultPreferences).to.have.property('test.true.boolean', 'true');
expect(fp.defaultPreferences).to.have.property('test.false.boolean', 'false');
});
});
describe('#updatePreferences', function() {
// compat node 0.8 & 0.10
var encoding = process.version.indexOf('v0.8.') == 0 ? 'utf8': {encoding: 'utf8'};
describe('should correctly output a string value in user.js', function() {
it('without new line characters', function() {
var fp = new FirefoxProfile();
fp.setPreference('test.string.value', 'test string value');
fp.updatePreferences();
var userPrefsContent = fs.readFileSync(fp.userPrefs, encoding);
expect(userPrefsContent).to.contain('user_pref("test.string.value", "test string value");\n');
});
it('with new line characters', function() {
var fp = new FirefoxProfile();
fp.setPreference('test.string.value', 'test string\nvalue');
fp.updatePreferences();
var userPrefsContent = fs.readFileSync(fp.userPrefs, encoding);
expect(userPrefsContent).to.contain('user_pref("test.string.value", "test string\\nvalue");\n');
});
});
it('should correctly output a boolean value in user.js', function() {
var fp = new FirefoxProfile();
fp.setPreference('test.true.boolean', true);
fp.setPreference('test.false.boolean', false);
fp.updatePreferences();
var userPrefsContent = fs.readFileSync(fp.userPrefs, encoding);
expect(userPrefsContent).to.contain('user_pref("test.true.boolean", true);\n');
expect(userPrefsContent).to.contain('user_pref("test.false.boolean", false);\n');
});
});
});

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