admin管理员组

文章数量:1022997

I have a question regarding JavaScript and methods by which its code can be run. As we know, there is some JavaScript code embedded in tags and it runs natively within browser window - that's quite mon and that's how the web pages currently work.

If we want interaction out of the box with the web page we are surfing, we must use tool such as GreaseMonkey and write our UserScripts that allow us to change page behavior to our desired one. This still needs us to open browser window and visit our target.

The question is: can we somehow run JavaScript code on a certain page without even opening browser window? I mean, in an ideal solution there would be a mand-line tool that'd allow us to call:

./clibrowser  userscript.js

In which script, for example, we could run some AJAX code to fetch data ing from queries and pass it to some other PHP script that's save it to database.

I think that this question simplifies to: are there any tools like "mand-line browser" with JavaScript engine? I know, that it may sound strange, but I am curious just because of the idea I have in my mind.

I have a question regarding JavaScript and methods by which its code can be run. As we know, there is some JavaScript code embedded in tags and it runs natively within browser window - that's quite mon and that's how the web pages currently work.

If we want interaction out of the box with the web page we are surfing, we must use tool such as GreaseMonkey and write our UserScripts that allow us to change page behavior to our desired one. This still needs us to open browser window and visit our target.

The question is: can we somehow run JavaScript code on a certain page without even opening browser window? I mean, in an ideal solution there would be a mand-line tool that'd allow us to call:

./clibrowser http://google. userscript.js

In which script, for example, we could run some AJAX code to fetch data ing from queries and pass it to some other PHP script that's save it to database.

I think that this question simplifies to: are there any tools like "mand-line browser" with JavaScript engine? I know, that it may sound strange, but I am curious just because of the idea I have in my mind.

Share Improve this question edited Nov 17, 2013 at 18:13 tshepang 12.5k25 gold badges98 silver badges139 bronze badges asked Dec 17, 2010 at 15:02 Tomasz KowalczykTomasz Kowalczyk 10.5k6 gold badges55 silver badges70 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Yes, there is. There is NodeJS, which runs on Chrome's V8 javascript engine: http://nodejs/.

There is also Rhino, which runs on Java: http://www.mozilla/rhino/.

The thing about these is that they don't include a "browser" as such... they are just javascript engines that can execute javascript, but don't provide the ability to parse/manipulate HTML, out of the box. However, there are javascript libraries built upon these engines that do simplify most of the work for you.

There is phantomjs: http://phantomjs which is a webkit-based headless browser with full support for javascript. It exposes an interface that lets you navigate to a page, interact with it and run whatever scripts you want in that page's context.

I have a question regarding JavaScript and methods by which its code can be run. As we know, there is some JavaScript code embedded in tags and it runs natively within browser window - that's quite mon and that's how the web pages currently work.

If we want interaction out of the box with the web page we are surfing, we must use tool such as GreaseMonkey and write our UserScripts that allow us to change page behavior to our desired one. This still needs us to open browser window and visit our target.

The question is: can we somehow run JavaScript code on a certain page without even opening browser window? I mean, in an ideal solution there would be a mand-line tool that'd allow us to call:

./clibrowser  userscript.js

In which script, for example, we could run some AJAX code to fetch data ing from queries and pass it to some other PHP script that's save it to database.

I think that this question simplifies to: are there any tools like "mand-line browser" with JavaScript engine? I know, that it may sound strange, but I am curious just because of the idea I have in my mind.

I have a question regarding JavaScript and methods by which its code can be run. As we know, there is some JavaScript code embedded in tags and it runs natively within browser window - that's quite mon and that's how the web pages currently work.

If we want interaction out of the box with the web page we are surfing, we must use tool such as GreaseMonkey and write our UserScripts that allow us to change page behavior to our desired one. This still needs us to open browser window and visit our target.

The question is: can we somehow run JavaScript code on a certain page without even opening browser window? I mean, in an ideal solution there would be a mand-line tool that'd allow us to call:

./clibrowser http://google. userscript.js

In which script, for example, we could run some AJAX code to fetch data ing from queries and pass it to some other PHP script that's save it to database.

I think that this question simplifies to: are there any tools like "mand-line browser" with JavaScript engine? I know, that it may sound strange, but I am curious just because of the idea I have in my mind.

Share Improve this question edited Nov 17, 2013 at 18:13 tshepang 12.5k25 gold badges98 silver badges139 bronze badges asked Dec 17, 2010 at 15:02 Tomasz KowalczykTomasz Kowalczyk 10.5k6 gold badges55 silver badges70 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Yes, there is. There is NodeJS, which runs on Chrome's V8 javascript engine: http://nodejs/.

There is also Rhino, which runs on Java: http://www.mozilla/rhino/.

The thing about these is that they don't include a "browser" as such... they are just javascript engines that can execute javascript, but don't provide the ability to parse/manipulate HTML, out of the box. However, there are javascript libraries built upon these engines that do simplify most of the work for you.

There is phantomjs: http://phantomjs which is a webkit-based headless browser with full support for javascript. It exposes an interface that lets you navigate to a page, interact with it and run whatever scripts you want in that page's context.

本文标签: Run JavaScript code on a page without showing browser windowStack Overflow