Open Bug 1639930 Opened 4 years ago Updated 4 years ago

Cannot navigate back to previous page when using window.location.assign in Google Maps Geocoder geocode callback

Categories

(Core :: DOM: Window and Location, defect, P3)

68 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: allison, Unassigned)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36

Steps to reproduce:

See code below to reproduce.
When assigning a new location from within the geocoder callback, the browser correctly redirects but is unable to redirect back to the previous page. This issue only happens in Firefox and only from within the geocoder callback. Adding a setTimeout before the assign redirect solves this issue, however, it shouldn't happen in the first place. The documentation for the Location object (https://html.spec.whatwg.org/multipage/history.html#location-object-setter-navigate) states that a replacement flag will not be added if any of three conditions are met. I've verified that the e.isTrusted is true, so this condition should be met and not replace the current location href.
Minimal code to reproduce the issue:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>

<body>
<div>
<p>Hello!</p>
<p>Here is some content</p>
<button id="button">Redirect</button>
</div>
<script>
const script = document.createElement("script");
script.src = https://maps.googleapis.com/maps/api/js?key=${API_KEY};
document.body.appendChild(script);

  script.onload = () => {
    document.getElementById("button").addEventListener("click", (e) => {
      e.preventDefault();
      const geocoder = new google.maps.Geocoder();
      geocoder.geocode(
        { address: "1600 Amphitheatre Parkway, Mountain View, CA" },
        (results, status) => {
          if (status === google.maps.GeocoderStatus.OK && e.isTrusted) {
            console.log("results: ", results);
            window.location.assign("https://www.amazon.com");
          }
        }
      );
    });
  };
</script>

</body>
</html>

Actual results:

Cannot navigate back to previous page.

Expected results:

Should be able to navigate back to previous page.

Component: Untriaged → DOM: Geolocation
Product: Firefox → Core
Component: DOM: Geolocation → DOM: Window and Location

Allison, could you perhaps attach the testcase as an attachment so that one could try it easily? Or upload it to some other server if the API key is needed?

Also, do you see any exceptions or warning in the web console, when .assign() doesn't work?

And the summary talks about going back but the test case seem to use .assign().
Which one is this about?

Flags: needinfo?(allison)
Attached file test.html

Olli Pettay,
I've attached the example code as an html file.

You will need to add your own google maps api key to the file in order to reproduce. You can create one here: https://developers.google.com/maps/documentation/javascript/get-api-key. Perhaps Mozilla has test api keys for bug testing purposes?

Once you have added an api key, open the html file in Firefox and click the 'Redirect' button. The page will be correctly redirected to amazon.com using window.location.assign("https://www.amazon.com"), however, once arriving at the correct location, the browser back button is disabled and the user is unable to navigate back to the previous page. This only happens when window.location.assign() is called from within Google Maps Geocoder geocode method's callback. The documentation for the geocoder can be found here: https://developers.google.com/maps/documentation/javascript/geocoding.

Let me know if you have any further questions. Thank you!

Flags: needinfo?(allison)

The severity field is not set for this bug.
:farre, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(afarre)
Severity: -- → S3
Flags: needinfo?(afarre)
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: