following case.
I have a python script that opens a firefox browser on windows which has a firefox addon installed that writes logs into the local storage.
Before I close the browser via python I would like to read out the log information out of the local storage of the firefox.
So how can I access the localStorage in the firefox?
Help very appreciated.
You will have to use PyXPCOM and the nsIDOMStorageManager interface.
Have a look at this tutorial to see how to use PyXPCOM.
You may start from this code (untested):
from xpcom import components
principal = (components.classes['#mozilla.org/scriptsecuritymanager;1']
.getService(components.interfaces.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(YOUR_URL))
dom_storage_manager = (components.classes['#mozilla.org/dom/localStorage-manager;1']
.getService(components.interfaces.nsIDOMStorageManager))
local_storage = dom_storage_manager.getLocalStorageForPrincipal(principal, YOUR_URL)
Related
Currently using this method as a legacy method.
this.prefService = Components
.classes["#mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
this.prefBranch = this.prefService.getBranch(root);
but i did not get a complete idea about how to use this in the webextension environment thunderbird .any api in order to use this feature ?
I solved my issue, by using Web Extension experiment.
Implemented the same legacy extension function with the Web Extension Experiment Specification and that solved my need at this moment.
the link mentioned below.
https://thunderbird-webextensions.readthedocs.io/en/68/how-to/experiments.html
https://firefox-source-docs.mozilla.org/toolkit/components/extensions/webextensions/functions.html
I think you can use the storage.local API (see documentation, it seems to work the same for Firefox and Thunderbird). This allows you to store data related to your add-on with something like:
let settingItem = browser.storage.local.set(
keys // object
)
and to retrieve or remove it after that (see available methods).
I have tried pretty much every way mentioned on SO and the docs and failed.
Specifically, I'm using WebdriverJS through Node.js.
I'd want a way to programatically make Firefox-Quantum use a proxy, which requires auth and port (i.e http://user:pass#host:port).
I don't mind to use an extension for this, but I don't know which one I could use for programmatic access.
I do not want a solution involving the authentication dialog popping up and asking for the auth.
I used to manage to do it on Firefox 56.0 using an extension called CloseProxy. (As per How to set proxy authentication (user & password) using python selenium)
However, CloseProxy is not supported on Firefox-Quantum.
This is my last attempt at this issue before resorting to going ahead and writing my own Webextension for this so I hope someone somewhere has the answer
Somethig like that should work:
var webdriver = require('selenium-webdriver'),
proxy = require('selenium-webdriver/proxy');
var driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.firefox())
.setProxy(proxy.manual({http: 'host:1234'}))
.build();
Actually there is a lot of info about this https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/proxy.html
You all know open npm package: https://www.npmjs.com/package/open
Using this package, one can write the following code:
var open = require('./node_modules/open/lib/open.js')
open('http://www.cnn.com')
and activating it by:
$ node app.js
will open a browser window of cnn.com.
I want my script to open this site and inject some code to the console. I mean that the browser will behave like I clicked F12, went to 'console' tab and typed in console the code:
alert('Hello World')
Do you know how to do it?
The open module is used to "Open a file or url in the user's preferred application."
It can open the preferred application (a browser in this case) but it cannot control it. In fact, it doesn't even know what browser will that be (or even if that will be a browser).
What you are asking for can be achieved with tools like PhantomJS ("PhantomJS is a headless WebKit scriptable with a JavaScript API."), Nightmare.js ("A high-level browser automation library.") or CasperJS ("Navigation scripting & testing for PhantomJS and SlimerJS"), see:
http://phantomjs.org/
http://www.nightmarejs.org/
http://casperjs.org/
I wan't to protect the code of my node-webkit desktop application packaged in an exe file.
The problem is not on the file directly but with the dedicated port for remote debugging.
Perhaps I haven't understood something but, on Windows, if I execute a "netstat -a -o" command, I see an open port associated to the application and if I open this port on my browser, I have a page with "Inspectable WebContents" and a link to the webkit application.
With this debug window, it's possible to access to all the sources of the app and I don't know how to disable this feature.
For now, I think there is no actual way to disable remote debugging in nw.js.
Even so, according to the wiki, remote debugging seems to only be executed through the command line switches. Therefore you can block the chromium command line switches (or only --remote-debugging-port) to prevent arbitrary remote debugging by user until nw.js supports disabling functionality of remote debugging.
For instance:
const gui = require('nw.gui');
const app = gui.App;
for (let element of app.fullArgv) {
// app.argv has only user's switches except for the chromium args
if (app.argv.indexOf(element) < 0) {
app.quit(1); // invalid args!
}
}
However, I am not quite sure the above code could protect your application code, because the nw.js is using Chromium internally. So that, the application code would be extracted in temporary folder on initialization. Whereas above solution isn't really protect your nw.js application. See more details: https://github.com/nwjs/nw.js/issues/269
Note: node-webkit has changed name to nw.js
I'm looking for a way to output Node variables directly into the google chrome browser console. The same way a console.log() works on the client side. Something like this for php. This would greatly speed up development.
NOTE:
Since the old answer (written in september 2014) refers to an older version of node-inspector, my instructions are not relevant anymore in 2017. Also, the documentation has gotten a lot better, so I have updated my original answer:
node-inspector is what you need.
It opens up an instance of Chrome with its developer tools for debugging.
It's also easy to use:
1. Install
$ npm install -g node-inspector
2. Start
$ node-debug app.js
Source: https://github.com/node-inspector/node-inspector
You might want to try NodeMonkey - https://github.com/jwarkentin/node-monkey
I know it's an old question but came on top of my Google search so maybe somebody will find my answer useful.
So you can use node --inspect-brk index.js
Now, all you have to do is basically just type chrome://inspect in your Chrome address bar and click Open dedicated DevTools for Node
In DevTools, now connected to Node, you’ll have all the Chrome DevTools features you’re used to:
Complete breakpoint debugging, stepping w/ blackboxing
Source maps for transpiled code
LiveEdit: JavaScript hot-swap evaluation w/ V8
Console evaluation with ES6 feature/object support and custom object formatting
Sampling JavaScript profiler w/ flamechart
Heap snapshot inspection, heap allocation timeline, allocation profiling
Asynchronous stacks for native promises
Hope that helped.
The closest thing to this I've seen is Node JS console object debug inspector
See this post for usage and potential issues: http://thomashunter.name/blog/nodejs-console-object-debug-inspector/
For users with nodejs on linux via ssh-shell (putty):
Problem with nodejs on linux-ssh-shell is, that you have no browser connected.
I tried all this solutions, but didnt get it to work.
So i worked out a solution with firebase (https://firebase.google.com), because my project uses firebase.
If you are familiar with firebase, than this is a great way. If not, firebase is worth using in combination with nodejs - and its free!
In the server-side-script (started with node) use a own function log():
// server-side:
// using new firebase v3 !
var fbRootRef = firebase.database();
var fbConsoleRef = fbRootRef.ref("/console");
var log = function(args) {
fbConsoleRef.set({'obj': args});
}
// inside your server-code:
log({'key':'value'});
On client-side you create a firebase-reference on this console-object:
// client side:
fbRootRef.child('/console').on('value', function(d) {
var v = d.val();
console.log(v);
});
Now everything logged on server-side with the log() - function is transferred in realtime to the firebase-database and from there triggering the client-console-reference and logged into the browsers console.
If anyone needs help, i will explain in more detail and could give a more extended version of this logging with types (console./log/warn/info), grouping with title-info (i.e. server says: (filename + line).
Setting up firebase for your project is done in max 30 minutes, inserting the console-function in 30 minutes. I think its worth the time!
You can use bonsole, a simple way to log something in browser. Even in Linux, you can go to the LAN's ip to check it.
The most simple way with least dependencies is using a WebSocket connection to send the messages to the browser. Any WebSocket example you can find on the internet will suffice to accomplish this. Everything else requires to be heavily integrated into the host system and wouldn't work if you want to actually run this on a remote server. You can also send commands to the server directly from the browser console this way.
Links:
https://www.npmjs.com/package/websocket
https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications