Geolocation permission denied when test run using chrome headless

Hello,

I’m trying to get the geolocation in the application I’m testing. Im getting a permission error message after clicking the geolocation button. I’m getting the message “Unable to get geolocation. error message: User denied to request for Geolocation”
Screen Shot 2022-03-18 at 5.49.10 pm

When Im using chrome browser the issue does not persist. This only happens when I use chrome headless browser. All my tests are running using chrome headless browser and would like to still use this browser in my tests.

I tried different solution that I’ve googled such as adding a pref value for the chrome headless browser. pref value was “profile.default_content_setting_values.geolocation”: 1, but still getting the same error.

Here is a snippet of my code to click the geolocation button. The script clicks the button then wait for the map and clear buttons to be displayed next.

    get_for_attribute_string = WebUI.getAttribute(findTestObject(Constants.PATH_PAGE + '/FormRecord/label_form_element', [('label') : label]), 'for')
//get geolocation
WebUI.click(findTestObject(Constants.PATH_PAGE_GENERAL + '/button_geolocation' , [('forAttribute') : get_for_attribute_string]))
WebUI.delay(5)
WebUI.waitForElementVisible(findTestObject(Constants.PATH_PAGE_GENERAL + '/input_geolocation_map' , [('forAttribute') : get_for_attribute_string]), 5)
WebUI.waitForElementVisible(findTestObject(Constants.PATH_PAGE_GENERAL + '/button_clear_location'), 5)

I hope someone can help me with my problem Thanks in advance