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.