Using var socket = chrome.sockets.tcpServer; in a chrome extension - google-chrome-extension

I was trying to open a tct server in a chrome extension browser action.
When I try to do it, an exception is shown in this line:
var socket = chrome.sockets.tcpServer;
The error is:
Is there a way to do it?

Related

AWS lambda not opening window using node.js

I have simple requirement wherein i need to open a window with given URL using node.js, which is deployed on AWS as Lambda function.
Following is the sample code I am trying, the execution of lambda function returns as Success, but no window is opened in any browser, i.e. the url is not launched. When I execute the same code on windows or linux, I can see a window getting launched.
function summaryHandler (event, context, callback) {
console.log('Will open google page');
var open = require('open');
open('http://www.google.com');
callback(null, 'Your window should be launched by now');
}
exports.summaryHandler = summaryHandler;
Can you please tell me where is the issue?
If you try to do this in Lambda, it would try to open the said webpage on the AWS server, not on your local machine. You could instead try to return a redirect to the webpage.
https://aws.amazon.com/blogs/compute/redirection-in-a-serverless-api-with-aws-lambda-and-amazon-api-gateway/

How to detect browser close event in node js?

I have used Electron(formerly Atom Shell) to create desktop app using NodeJS.
I am using following code to open an url into browser
var spawn = require('child_process').spawn
spawn('open', ['http://www.stackoverflow.com']);
Please note that I am not using Electron BrowserWindow, this is a regular browser window.
I want to perform an action when user closes this browser window. How do I detect close event of this spawned browser?
Try utilizing the event emitter
var spawn = require('child_process').spawn,
browser = spawn('open', ['http://www.stackoverflow.com']);
browser.on('close', function() {
// Handle event
});

Listen to click event in web page chrome extension

Am developing a chrome extension. Am injecting a script in a wbpage using contentscript as follows:
var s = document.createElement('script');
s.src = chrome.extension.getURL("script.js");
(document.head||document.documentElement).appendChild(s);
My script.js:
$.post("https://www.example.com/srv/example/", function(html){
$("body").prepend(html);
});
Now, i would like to listen to a button click event in the webpage DOM ? How to achieve this?
You can listen with
document.body.addEventListener('click', yourListenerFunction, true);
BTW, you're executing your content script in a very odd way. The usual is using some code in your background.js, like:
chrome.tabs.executeScript(tabId, {file:"yourScriptFile.js"});
I recommend this https://developer.chrome.com/extensions/overview

Connect manually with sails.io.js

I'm trying to use sails.io.js in a chrome extension.
I'm setting manually the url of my sails server with the line :
io.sails.url = "http://localhost:1337";
But I would like to get the url from the chrome local storage (to save the url not directly in the code). But the problem is, as said here:
You get 1 clock tick after the import before the socket attempts to
connect.
So if I get the URL from the chrome local storage with :
storage.get('url', function(result){
var url = result.url;
io.sails.url = url ;
});
It's too late! The options must be set just after the sails.io.js code..
So I was thinking about disabling autoConnect with :
io.sails.autoConnect = false;
(As said there)
But now my question is : How can I can connect manually with io.sails ?
I've tried io.sails.connect(), did not work. Any ideas ?
Thank you very much,
Well, it's yours to customize but if you want to get away with minimal amount of changes to sails.io.js then you could
change setTimeout to io.sails.doit = function() {
throw away the io.sails.autoConnect check
call io.sails.doit(..) when you're ready
Also, if you want to pass something over during the handshake you can add {'query':'param='+value} as second argument to io.connect(io.sails.url);
It is then available in sails app's config/sockets.js through socket.handshake.query.param.

Generate node-xmpp script for browser

I am developing an application on php. I need a chat on xmpp nodejs. Sending a message will go from web page.
I found enter link description here. In terminal everything works fine. But how do I attach client script to the browser?
I generate script by:browserify node_modules/node-xmpp/lib/node-xmpp-browserify.js > nodeXmpp.js and attach it to web page:
Then trying to use it:
$(document).ready(funcrion(){
var client = new XMPP.Client({
jid: 'user#example.com',
password: 'password'
});
});
And chrome console telling me:
Cannot load StringPrep-0.2.3 bindings (using fallback). You may need to npm install node-stringprep nodeXmpp.js:3669
event.returnValue is deprecated. Please use the standard event.preventDefault() instead. jquery.js:3254
Uncaught TypeError: Object # has no method 'resolveSrv'
Object # - its "dns".
And before generate script i install node-stringprep.
Question is how build xmpp client script for browser.
You didn't post your code, but the following should work fine:
require('node-xmpp/lib/node-xmpp-browserify.js');
var client = new XMPP.Client(opts);

Resources