Erlang: is there a module analogous to Python "webbrowser"? - browser

I've used Python webbrowser module and I would love something equivalent in Erlang. What I am trying to do is open a browser window/tab from Erlang.
I can't find anything in the official Erlang documentation. Is there such a thing?

I assume you mean the Python webbrowser module, not webserver. The code for this module is instructive; it looks for various browsers and picks the best option. It interacts with the browser by running a shell command. Firefox supports a -remote command line argument to control an existing Firefox process. (IE seems to be handled simply by passing the url to the iexplore.exe)
The module also detects if it's running on Windows and tries to find out the Windows default browser and use that. Likewise, on Mac OS X, it uses the open command, which will use the default browser.
You should be able to implement this with open_port/2.

Related

I wonder if this is Python IDLE

At first, I'm not good at English but I'm doing my best, thank you.
I connected Amazon Lightsail and installed python36.
It is the list I installed.
python36.x86_64
python36-devel.x86_64
python36-libs.x86_64
python36-pip.noarch
Then I entered shell as shown in picture below after typing 'python3'.
At https://realpython.com/python-idle/#what-is-python-idle, How to Use the Python IDLE Shell's first image, it looks very similar to the image I uploaded.
So I think it is Python IDLE but I'm not sure yet.
Because at https://www.centos.org/forums/viewtopic.php?t=53908, 'python34-tools' contains idle3.
What? I'm not installed 'python36-tools'!
I installed 'python36-tools' and typed 'idle3' but there's an error, 'command not found'.
Even according to https://centos.pkgs.org/7/puias-unsupported-x86_64/python36-idle-3.6.6-1.sdl7.x86_64.rpm.html, it is definitely Python IDLE!
What's the right thing? I'm so confused.
I wanted to know more, so visit https://docs.python.org/ko/3.6/whatsnew/3.6.html and find this, 'The IDLE features formerly implemented as extensions have been reimplemented as normal features.'
It can be translated like this?
'Starting with version 3.6.3, you don't have to install idle3 separately. Just type python3 for use Python IDLE.'
I searched the information related to the above and couldn't find anything.
Please help me!
IDLE is a GUI application, with menus and windows. So you need to use a Linux/macos/windows desktop environment, it does not run in a terminal window.
It actually looks like this: https://www.youtube.com/watch?v=bOvqYw1SZJg
It starts in a standard python interactive shell, such as your screen shot.
But being a desktop app, it allows you to have multiple editor windows open with source files, and it has GUI debugging tools. IDLE is rudimentary, but also very simple (which can be a good thing).
I think there is a lot to be said for learning python in a real desktop environment, with multiple windows and friendly, easy to use debuggers.
There are cloud IDEs for python, but I don't think they are a good step for newcomers. The debugging is not very good, for instance.
However, jupyter is a good option for learning python, I think.
E.g.: https://realpython.com/jupyter-notebook-introduction/
Jupyter runs a webserver and you edit python in interactive workbooks which you open in a browser. I suppose it is a cloud IDE.
This is a short video of running it on Windows ... https://www.youtube.com/watch?v=jZ952vChhuI
jump to about the 2m mark to see it running.
To be honest, it is arguably a better place to start than IDLE.You could run the server part of this from lightsail, but you will probably need to configure your lightsail instance to open the ports needed to server jupyter's web pages.
But if you want to start with IDLE, you need python running on a desktop. A linux desktop is a very good choice. You can set up a desktop linux, such as ubuntu, in virtualbox if all you have is Windows.
However, if after all of that, you are going to do python from the command line, you should learn about
* virtual environments
* once you set one up, do pip install ipythonto get a better version of the python shell.
As others said, python3 on a non-Windows command line starts python in interactive mode. To start IDLE on a command line, use python3 -m idlelib.

linux or windows terminal over the web

I'm planing to make a web app which will allow you to have a Linux Terminal on a web page so that you can execute any command an get the response as if you were in front of your linux terminal.
I planed to use NodeJS as it is server side JavaScript, asynchronous and fast.
Also I saw this wich does exactly what i'm trying to do, I peeked in the source code, but didn't found something useful, I also analysed it with google chrome developer tools on the network tab, but there is absolutely nothing even while executing some commands and getting responses. How is this possible ? what technology do you think they used ?
So I wanted to get your advice, your experience in order to start it the right way.
I firstly decided to use NodeJS, but if there is another programming language or Framework more appropriate for this kind of application please let me know.
If you want a real terminal in the browser using node.js on the backend, you might give tty.js a try.
Alternatively you can use the pty.js module manually which is used by tty.js. Along with that, you could also use xterm for doing the browser-side terminal emulation.

Google chrome extension with NPAPI moving to NaCl

I have recently developed a google chrome extension that uses an NPAPI plugin made using the FireBreath framework. I just now found out that google will shortly discontinue these types of plugins and eventually ban all existing extensions that use them. So, I would like to eventually move to the NaCl / PPAPI architecture, but I am not sure if this architecture can even support what I am currently doing in the NPAPI plugin.
In my current NPAPI plugin I am supporting OSX and Windows. On the OSX version, the plugin executes the system() function which executes a small 1 line applescript. It looks like this:
osascript -e 'tell app ...
On the windows version, it executes functions in a COM library. Both versions end up doing the same exact thing. Another option I have is executing a python script, if I were to go this route, I would most likely want to embed python in the native component.
Is any of this possible anymore with NaCl / PPAPI?
The ability to run arbitrary system() function or execute arbitrary functions from a COM library is #1 reason for NPAPI deprecation. Ditto for execution of a python script (you can execute python script in NaCl, of course - but it'll not be able to call system() function or a COM library either).
It's not news: as was noted in the Chrome Comic book on the day of Chromium release NPAPI plugins are unrestricted and that it's a big problem: http://www.google.com/googlebooks/chrome/small_30.html
It was obvious even back then that this situation can only be tolerated for so long. Plugins were tolerated for five years because some important things were unimplemenatble without them but now it's time to kill plugins and make sure nothing in browser can access OS directly.
If you want to implement some functionality which can not be implemented in browser currently because there are no appropriate API the right way is to ask about it on chromium-dev and add this API to Chromium (and perhaps other browsers, too). For example access to COM ports (not libraries) was added recently (see http://developer.chrome.com/apps/app_hardware.html).
Since you are already using an extension, you may want to look at Native Messaging as a replacement for your use of NPAPI.
If you don't need an interaction between browser and the application, you can use external protocol support. You need to register protocol in the registry on Windows. I don't know how external protocols work on OSX. When user clicks external protocol link, Chrome shows a dialog which allows user to launch the application.

Selenium on shared gui-less host

I need to run Selenium (or another webscraping tool that can handle javascript) on a remote linux host (Webfaction). I am using Python.
Is this possible? The server is gui-less so I can't run browsers. Or can I, if I use PyVirtualDisplay?
What about running Selenium with HtmlUnit?
I have tried using Selenium with Selenium/PyVirtualDisplay/ChromeDriver, but keep getting various error messages. So I'm wondering if this is even possible before I continue to debug something impossible.
If you need to handle JavaScript Selenium/Webdriver seems to be a good solution.
If you need to run headless, GhostDriver (instead of ChromeDriver) is an excellent alternative. It is based on PhantomJS, a headless browser based itself on Webkit. It has full JS-support.

How do I programatically control a Chrome instance from the command line?

How do I control a running Google Chrome instance from the command line? I'm hoping there's something like a -remote flag that will allow me to send in some javascript or somesuch. In particular, I would like to reload the topmost document on the foremost window.
I'm especially interested in Linux/MacOS solutions.
Take a look at http://code.google.com/p/chromedevtools/ . It might be you can use the Debugging Protocol to do the job.
There is also an Ruby Client.
There is also chromix.
You can use this command line tool if you're on a Mac - it uses the Chrome Scripting API, I guess
https://github.com/prasmussen/chrome-cli

Resources