Playwright azure function doesn't install chromium Python based

Question:

I tried to execute an azure function based on Python and get this problem

PlayWright Install

PLAYWRITH_BROWSERS_PATH=0 is already set, also I tried put playwright install on requeriments.txt
but it doesn’t work either. I’ve thinking in add a task in tasks.json on .vscode path but I don’t know how to do it.

Asked By: Miguel Angel M

||

Answers:

PLAYWRITH_BROWSERS_PATH=0

Please make sure your above configuration was correct. There are some spelling mistakes in the settings. Its like PLAYWRIGHT_BROWSERS_PATH = 0

In your local.settings.json it should be

{

"IsEncrypted": false,

    "Values": {
    
        "AzureWebJobsStorage": "",
        
        "FUNCTIONS_WORKER_RUNTIME": "python",
        
        "PLAYWRIGHT_BROWSERS_PATH": "0"
    
    }

}

And In your requirement.txt file it should be

azure-functions
playwright==1.18.0

here we can see the playwright running in local as well as azure after deployment
Local:
enter image description here

Azure:

enter image description here

enter image description here

You can solve this by installing the drivers into the function project and defining the location in PLAYWRIGHT_BROWSERS_PATH, as follows:

  1. Create a bin folder in the project, here we want to store the drivers
  2. Install the drivers in the bin folder using the following command, this installs the drivers in a pw-browers folder in the bin:
PLAYWRIGHT_BROWSERS_PATH=./bin/pw-browsers python -m playwright install
  1. Define the path to the drivers in local.settings.json AND in the Azure function project itself:
{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "PLAYWRIGHT_BROWSERS_PATH": "./bin/pw-browsers"
  }
}

EDIT:
alternative solution:
https://github.com/anthonychu/20220303-python-func-playwright

Answered By: Jeroen Vermunt