There is my server A and third-party server B.
I want to run the js script on server B and get the html back after executing this script (or even better a particular div from this html'a).
How can this be done, maybe there are ready-made libraries? Interested in solutions for both js and php. The option to inject through the browser extension does not interest.


Update from comments :

The user does not even suspect the presence of the server B. Let me give this example: the user clicks on the link on server A, and at this time the php or js script in the background, you can say, opens a page on server B, runs the script there (let's say , a script that clicks a button that opens a pop-up window on server B page, in which certain text is displayed), and the user sees on the server A the text from this window.

  • You can get the html document on the client and search for the desired div - Mr. Black
  • Do you want to execute js script, which is located on server A, on server B? Or execute a script that is located on server B on the same server B? - VenZell
  • @VenZell first option (run js script, which is on server A, on server B) - ilyaspark
  • What kind of actions should this script perform with server B contents? - VenZell
  • 2
    I think that's all worth adding to the question itself. - Dmitriy Simushev

1 answer 1

You need a headless browser, for example, PhantomJS .
For him, there is a PHP wrapper: PHP PhantomJS .

PhantomJS will allow you to execute arbitrary javascript code on the specified page. The principle of operation is similar to the action of extensions in the browser. The script you need will be included and executed in the context of the landing page.

Here are a couple of articles on this:
Writing parser sites using PhantomJS
Introducing PhantomJS in practice

  • This is what I need, thank you so much! - ilyaspark