Execute JS for MapBox via Playwright

My goal is to be able to zoom in on a MapBox map when running automated web tests using playwright.

I have found that in the browsers console i can type map.zoomTo(15) and the map zoom in exactly how I want it to. However, when I try and do this in a test using:

page.evaluate("""
          map.setZoom(15);
              """)

I get the error playwright._impl._errors.Error: ReferenceError: map is not defined

Tring,

  page.evaluate("""
            window.map.setZoom(15);
                """)

I get the error playwright._impl._errors.Error: TypeError: Cannot read properties of undefined (reading 'setZoom')

I don’t understand why Playwright evaluate is different to issuing it on the browsers console.

The second example looks like map is defined so to me means the map should be initialized, but just doesn’t have access to the setZoom function.

Any help would be greatly apricated, reading the playwright doc makes it sound like it would be working.

Example code:

from playwright.sync_api import sync_playwright

pw = sync_playwright().start()
browser = pw.chromium.launch(headless=False, slow_mo=0)

browser_context = browser.new_context()
page = browser_context.new_page()

page.goto("http://127.0.0.1/map")

page.evaluate("""
          map.setZoom(15);
              """)

I don’t have a public facing version of the page available to me.