Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

firefox-client

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firefox-client - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

156

buptest.js

@@ -1,150 +0,28 @@

var FirefoxClient = require("./lib/browser.js");
var FirefoxClient = require("./index");
var client = new FirefoxClient();
var client = new FirefoxClient({log: false});
client.connect(function() {
console.log("client");
client.connect(6000, function() {
client.listTabs(function(err, tabs) {
var tab = tabs[0];
testTab(tab);
console.log("first tab:", tabs[0].url);
testSheetSource(tabs[0]);
});
});
function testCachedLogs(tab) {
tab.Console.startLogging(function() {
console.log("started logging");
tab.Console.getCachedLogs(function(err, resp) {
console.log("cached", resp);
});
tab.Console.getCachedLogs(function(err, resp) {
console.log("cached", resp);
});
})
}
function testTab(tab) {
//testCachedLogs(tab);
//testAttach(tab);
testReload(tab);
//testNavigateTo(tab);
//testDOM(tab);
//testLogs(tab);
//testNetwork(tab);
//testConsole(tab);
}
function testAttach(tab) {
tab.attach(function(resp) {
console.log("attach resp:", resp);
});
}
function testReload(tab) {
tab.DOM.document(function(err, doc) {
console.log("hola", doc.actor);
});
tab.attach(function(err, resp) {
function testSheetSource(tab) {
tab.StyleSheets.getStyleSheets(function(err, sheets) {
if (err) throw err;
tab.on("navigate", function() {
tab.DOM.document(function(err, doc) {
if (err) throw err.message;
console.log("hola again", doc.actor);
});
})
tab.reload();
});
}
sheets[0].getSource(function(err, source) {
if (err) throw err;
function testNavigateTo(tab) {
tab.navigateTo("http://www.google.com");
}
//console.log(source.);
console.log(source.length);
function testConsole(tab) {
tab.Console.evaluateJS("window", function(resp) {
var result = resp.result;
// result.ownPropertyNames(function(names) {
// console.log("num properties: ", names.length);
// });
result.prototype(function(resp) {
console.log(resp);
})
result.propertyValue('document', function(value) {
console.log("document value:", value.class);
})
});
}
function testNetwork(tab) {
tab.Network.on("network-event", function(event) {
console.log("network event: ", event.url);
});
tab.Network.startLogging();
var request = {
url: "https://github.com/harthur/some-json/raw/gh-pages/1.json",
method: "GET",
headers: [{name: "test-header", value: "test-value"}]
};
tab.Network.sendHTTPRequest(request, function(networkEvent) {
networkEvent.getResponseHeaders(function(message) {
console.log("got event headers:" + JSON.stringify(message));
})
networkEvent.on("update", function(type, data) {
console.log("on update " + type);
if (type == "responseContent") {
networkEvent.getResponseContent(function(message) {
console.log("got event headers:" + JSON.stringify(message));
})
}
})
});
}
function testLogs(tab) {
tab.Logs.getLogs(function(resp) {
console.log("logs:", resp);
});
tab.Logs.on("page-error", function(error) {
console.log("received error: " + error.errorMessage);
});
tab.Logs.on("console-api-call", function(call) {
console.log("made console call: console." + call.level + "()");
});
tab.Logs.startLogging();
}
function testStyleSheets(tab) {
tab.StyleSheets.addStyleSheet("* { color: red; } ", function(sheet) {
console.log("added style sheet to document ", sheet.ruleCount);
});
}
function testDOM(tab) {
tab.DOM.document(function(doc) {
doc.querySelector(".event", function(node) {
node.outerHTML(function(html) {
//console.log(html);
});
node.siblings(function(siblings) {
console.log(siblings.length);
});
node.nextSibling(function(sibling) {
console.log(sibling.nodeName);
});
var className = node.getAttribute("class");
console.log("class: ", className);
node.setAttribute("class", "no-class", function() {
console.log("attr set");
source.substring(0, 10, function(err, str) {
if (err) throw err;
console.log("string: ", str);
})

@@ -151,0 +29,0 @@ })

5

lib/client.js

@@ -143,3 +143,6 @@ var net = require("net"),

if (!message.from) {
throw new Error("Server didn't specify an actor");
if (message.error) {
throw new Error(message.message);
}
throw new Error("Server didn't specify an actor: " + JSON.stringify(message));
}

@@ -146,0 +149,0 @@

@@ -103,2 +103,6 @@ var extend = require("./extend"),

highlight: function(cb) {
this.nodeRequest('highlight', cb);
},
release: function(cb) {

@@ -105,0 +109,0 @@ this.nodeRequest('releaseNode', cb);

@@ -20,3 +20,3 @@ var extend = require("./extend");

addStyleSheet: function(text, cb) {
this.request('newStyleSheet', { text: text }, function(resp) {
this.request('addStyleSheet', { text: text }, function(resp) {
return new StyleSheet(this.client, resp.styleSheet);

@@ -61,5 +61,34 @@ }.bind(this), cb);

getOriginalSources: function(cb) {
this.request('getOriginalSources', function(resp) {
if (resp.originalSources === null) {
return [];
}
return resp.originalSources.map(function(form) {
return new OriginalSource(this.client, form);
}.bind(this));
}.bind(this), cb);
},
update: function(text, cb) {
this.request('update', { text: text }, cb);
this.request('update', { text: text, transition: true }, cb);
}
})
});
function OriginalSource(client, source) {
console.log("source", source);
this.initialize(client, source.actor);
this.source = source;
}
OriginalSource.prototype = extend(ClientMethods, {
get url() {
return this.source.url
},
getText: function(cb) {
this.request('getText', cb);
}
});

@@ -27,3 +27,3 @@ var extend = require("./extend"),

if (!this._StyleSheets) {
this._StyleSheets = new StyleSheets(this.client, this.tab.styleEditorActor);
this._StyleSheets = new StyleSheets(this.client, this.tab.styleSheetsActor);
}

@@ -30,0 +30,0 @@ return this._StyleSheets;

{
"name": "firefox-client",
"description": "Firefox remote debugging client",
"version": "0.0.3",
"version": "0.1.0",
"author": "Heather Arthur <fayearthur@gmail.com>",

@@ -6,0 +6,0 @@ "main": "index.js",

# firefox-client
`firefox-client` is a [node](nodejs.org) library for remote debugging Firefox.
`firefox-client` is a [node](nodejs.org) library for remote debugging Firefox. You can use it to make things like [fxconsole](https://github.com/harthur/fxconsole), a remote JavaScript REPL.
```javascript
var FirefoxClient = require("firefox-client");
var client = new FirefoxClient();
client.connect(6000, function() {
client.listTabs(function(err, tabs) {
console.log("first tab:", tabs[0].url);
});
});
```
## Install

@@ -26,25 +38,14 @@ With [node.js](http://nodejs.org/) npm package manager:

## Usage
### Firefox OS Simulator
A limited set of the API (`Console`, `StyleSheets`) is compatible with the [Simulator 4.0](https://addons.mozilla.org/en-US/firefox/addon/firefox-os-simulator/). See the [wiki instructions](https://github.com/harthur/firefox-client/wiki/Firefox-OS-Simulator-Instructions) for connecting.
Use firefox-client from your node program with:
`client.listTabs()` will list the currently open apps in the Simulator.
```javascript
var FirefoxClient = require("firefox-client");
var client = new FirefoxClient();
client.connect(6000, function() {
client.listTabs(function(err, tabs) {
console.log("first tab:", tabs[0].url);
});
});
```
## Compatibility
This library is compatible with [Firefox Nightly](http://nightly.mozilla.org/).
This latest version of the library will stay compatible with [Firefox Nightly](http://nightly.mozilla.org/). Almost all of it will be compatible with [Firefox Aurora](http://www.mozilla.org/en-US/firefox/aurora/) as well.
## API
A `FirefoxClient` is the entry point to the API. After connecting, get a `Tab` object with `listTabs()` or `selectedTab()`. Once you have a `Tab`, you can call methods and listen to events from the tab's modules, `Console` or `Network`. There are also experimental `DOM` and `StyleSheets` tab modules.
A `FirefoxClient` is the entry point to the API. After connecting, get a `Tab` object with `listTabs()` or `selectedTab()`. Once you have a `Tab`, you can call methods and listen to events from the tab's modules, `Console` or `Network`. There are also experimental `DOM` and `StyleSheets` tab modules, and an upcoming `Debugger` module.

@@ -51,0 +52,0 @@ #### Methods

@@ -1,10 +0,54 @@

var FirefoxClient = require("./index");
var assert = require('assert'),
FirefoxClient = require("./index");
var client = new FirefoxClient();
client.connect(6000, function() {
client.listTabs(function(err, tabs) {
console.log("first tab:", tabs[0].url);
client.disconnect();
var url = "file:///Users/harth/repos/sass-wwcode/index.html";
loadUrl(url, function(tab) {
tab.StyleSheets.getStyleSheets(function(err, sheets) {
var sheet = sheets[1];
sheet.getOriginalSources(function(err, sources) {
console.log(err);
console.log(sources[0].url);
sources[0].getText(function(err, resp) {
console.log(err);
console.log(resp);
})
});
console.log(sheet.href);
});
});
})
/**
* Helper functions
*/
function loadUrl(url, callback) {
getFirstTab(function(tab) {
console.log("GOT TAB");
tab.navigateTo(url);
tab.once("navigate", function() {
console.log("NAVIGATED");
callback(tab);
});
});
}
function getFirstTab(callback) {
var client = new FirefoxClient({log: true});
client.connect(function() {
client.listTabs(function(err, tabs) {
if (err) throw err;
var tab = tabs[0];
// attach so we can receive load events
tab.attach(function(err) {
if (err) throw err;
callback(tab);
})
});
});
}

@@ -292,2 +292,11 @@ var assert = require("assert"),

describe('highlight()', function() {
it('should highlight node', function(done) {
node.highlight(function(err, resp) {
assert.strictEqual(err, null);
done();
})
})
})
/* MUST BE LAST */

@@ -294,0 +303,0 @@ describe('remove()', function() {

@@ -93,1 +93,11 @@ var assert = require("assert"),

})
describe('StyleSheet.getOriginalSources()', function() {
it('should get no original sources', function(done) {
styleSheet.getOriginalSources(function(err, resp) {
assert.strictEqual(err, null);
assert.deepEqual(resp, []);
done();
})
})
})

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