NodeJS: Opening new tab instead of default user browser - node.js

I am working with third-party code (npm package) which uses opn (another npm package) to open default user browser during authorization. Instead of this, I want to open a new tab in the existing browser by sending some kind of request to the frontend. As I don't want to rewrite/copy all third-party code to actually change only one line inside, do you have any ideas how can I achieve this other way?
Will it be possible to detect action like opening browser and send the request to frontend instead? I know that opn spawns node child process.
Do you know if I can somehow efficiently change one of the third party code files so other files from this package will use my code instead? I could edit code inside node_modules to fulfil my requirements and never update this npm package but this sounds like a terrible idea.

If you want to open a new tab you should use Chrome DevTools Protocol.
You can read more here
https://github.com/cyrus-and/chrome-remote-interface
I guess you can't catch an 'open browser' event. But it should be possible to ask periodicaly the browser by something like 'chrome-remote-interface' npm package.

Related

Safe way to load third party module in NodeJs application

I am quite new in NodeJs and here is my issue:
I am developing a small app using Express.
In this app, I want to open a door for third party to install a kind of plugin. The idea is I have a "plugin" folder and they can create a plugin with a bootstrap file like "bootstrap.js"
From this file, they can define route...etc.
The main application will crawl the plugin folder and load the plugin automatically by requiring "bootstrap.js" file.
The problem is from the "bootstrap.js" file they can access everything like the app, request, route object by requiring Node module and modify them.
I want to prevent this from happing. I don't want the plugin to have access to main objects (Express app, request, route. ...) because it could make the application a mess.
Is there any way in Node when I can load a js file and prevent that file to execute something not allowed?
Thank you so much for your help

How EditThisCookie can edit value of Local HttpOnly Cookie from Chrome?

I need to edit locally stored HtppOnly cookies because my java program doesn't have browser capability so that I intent it to browser to view and manage same functions. But now the remote server has been updated and they use HttpOnly cookies (for security reasons) which canNOT be read by document.cookie function or any other js code. So that I wanna try to write chrome extension but before this I need to understand background process of EditThisCookie because I can edit value of cookie via this extension.
So now my question is start here. I look for source code from github but after tracking extensions apply click functions to find its background process but it uses jquery call (I really dont understand all codes what does and how does it run so I need your help) and it does something and I want to know what is that. After that I can write my own code. Thanks.

Responsive design for working website

I'm beginner web-developer, front-end only. Sometimes i need to make existing working websites to be responsive. I use browser extension(Styler for Chrome), that show me window where i can insert my styles, which will be applied for a page. But it looks little difficult(need to write code in my text-editor, copy this to extension form, than again, again and again...). Is there a way, to integrate my local stylesheet, to existing website, make changes only in my editor and reload page automatically, like with local page? I've found something on LiveReload website -
http://feedback.livereload.com/knowledgebase/articles/86220-preview-css-changes-against-a-live-site-then-uplo, but I can't use their app, cause i'm on windows(LiveReload is still in beta on it). If anybody use similar, can you please explain how to get it to work? Thanks.
In process of expiriencing I found simple solution for this:
Need to install Chrome extension(CSS Inject).
Run web-server on your machine which will host your css file for injecting(CSS Inject works only with HTTP) and insert it to CSS Inject, in my situation it looks like - http:// adapt/css/style.css
Need livereload server. I'am using node.js and this package https://www.npmjs.com/package/livereload for this.
Create file in your web-site root(for example server.js)
Paste this code in server.js:
var livereload = require('livereload'),
server = livereload.createServer();
server.watch(__dirname + "/css");
console.log('waiting for changes');
Go to your live website and activate CSS Inject.
run node ./server.js
That's it. You can now modify your styles localy and see changes on real website.
If anybody knows better solution(using API from this package https://www.npmjs.com/package/livereload#api-options, specifically overrideURL option) or have better expirience with node.js and understang how to implemet it, please post your solution here, I will be grateful.

node-webkit http.Server and page change

I write an application using node-webkit. I want to use HTTP for network communication between computers, running my app. Can I change current page without server restart if server was started from the page?
I thought about child process, but I want to shutdown the server with my application. I don't want to use special network request to the server to close it.
Can I change current page without server restart?
Can I save child process object while page changing?
Do you know other way to do this?
P.S. Sorry for my english.
I found the answer in the node-webkit documentation.
In node-webkit, you can basically do the same thing by using
window.location, you can install it in the onclick event of a link and
node-webkit will navigate to a new page when user clicks it. But by
doing this you would lose everything in window context, you can save
everything in cookies like old web pages, or you can save things in
the global variable, which resides in Node.js's context and will live
through your app.

How can I pass a message from outside URL to my Chrome Extension?

I know there's a way for extensions and pages to communicate locally, but I need to send a message from an outside URL, have my Chrome Extension listen for it.
I have tried easyXDM in the background page, but it seems to stop listening after awhile, as if Google "turns off" the Javascript in the background page after awhile.
I think you may try some walk around and build a site with some specific data structure, and then implement a content script which will look for this specific that specific data structure, and when i finds one it can fetch the data you want to be passed to your extension.
Yes, you need a content script that communicates with the page using DOM Events.. Instructions on how to do that are here:
http://code.google.com/chrome/extensions/content_scripts.html#host-page-communication

Resources