Documentation

    Amazon Web Services

    Microsoft Azure

    RapidAPI

    APILayer

Last Update: 2024-10-14

Playwright on Headless Ubuntu


Table of Content


Launch Playwright on Headless Ubuntu
Connect to your VM via SSH
Deploy files on your VM remotely
Run our sample code and develop your own scripts
Run Scripts in the Background After Closing the SSH Window
Troubleshooting

Launch Playwright on Headless Ubuntu

Navigate to our listing page on the AWS Marketplace and click 'Continue to Subscribe'.

On the subsequent page, review and accept our terms by selecting 'Accept Terms'.

Once the subscription process is complete, select 'Continue to Configuration'.

Choose the region where you wish to deploy the virtual machine, then click 'Continue to Launch'.

On the final page, select the instance type you wish to use (the recommended instance type is pre-selected) and review the other launch options. Then, click 'Launch'.

After launching, you can view your instance in the EC2 Management Console.

Connect to your VM via SSH


Please see the official documentation for detailed instructions on how to connect to a virtual machine with SSH.

Go to the EC2 Management Console and select the virtual machine to obtain its Public IPv4 address.

Open a Command Prompt / Terminal window and navigate to the directory where your created .pem key file is located. You can connect to your VM with the user 'ubuntu' by executing the following command:

ssh -i <name-of-key-file.pem> ubuntu@<public-ip>

Deploy files on your VM remotely

Download and install WinSCP or any other SCP client of your choice.

Choose 'SFTP' as the file protocol and enter the public IP address of your instance, using 'ubuntu' as the username.

Click on 'Advanced'.

In the left-side menu, select 'Authentication'. Under Authentication parameters, select the key file you created when you launched the virtual machine. When prompted, convert the .pem key file to PuTTY format.

Close the Authentication window by clicking on 'OK', and connect to the virtual machine by clicking on 'Login'.

Run our sample code and develop your own scripts

Connect to the terminal via SSH and log in as the user 'ubuntu'.

Navigate to the /home/ubuntu/Playwright/NodeJS directory by entering:

cd /home/ubuntu/Playwright/NodeJS

Run our sample code by using:

node script.js

Note: The first execution after startup can be very slow, especially on instances with low memory. There's a chance the browser might run out of memory. Performance should improve over time.

You can find the screenshots taken by using the command:

ls

Edit the file by entering:

nano script.js

Alternatively, you can deploy your scripts with an SCP tool.

Run the modified scripts again by using:

node script.js
Run Scripts in the Background After Closing the SSH Window


Connect to the terminal via SSH by logging in with your created user account (the default username is 'azureuser'). For guidance, refer to the chapter titled 'Connect to Your VM via SSH'.

Start a new tmux session by entering the following command:

tmux

Start the script you wish to run in the background.

To detach the tmux session while keeping your script running in the background, press CTRL+b followed by d. You can now safely close the SSH session; your script will continue to run inside tmux.

To resume your tmux session at any time, use the command:

tmux attach

Troubleshooting

How can I cancel my subscription?

To cancel your subscription, follow these steps:

  1. Go to the AWS Marketplace Console at https://aws.amazon.com/marketplace/library. Ensure that you are logged into the account that is subscribed to the product you want to cancel.
  2. Find the product you want to cancel and click on 'Manage.'
  3. Click on 'Actions' and then select 'Cancel subscription.'

For more detailed instructions, visit the AWS Marketplace Buyer Guide at https://docs.aws.amazon.com/marketplace/latest/buyerguide/cancel-subscription.html.