Open Bug 1853441 Opened 1 year ago Updated 1 year ago

window.close() stop working after window.location.assign()

Categories

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

Firefox 117
defect

Tracking

()

UNCONFIRMED

People

(Reporter: chenkaichn, Unassigned)

Details

Attachments

(1 file)

976 bytes, text/x-python-script
Details

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

Steps to reproduce:

Here's a demo app using flask which can help reproduce the bug. Steps to repro

  1. Save code below to to flask-app.py, and start the app with "flask --app flask-app run"
  2. Open the app from the url in the console, like http://127.0.0.1:5000
  3. Click on the "Open popup assign" button, it will open a popup
  4. In the popup, click the "Assign Location" button, it will redirect to google.com
  5. Open the dev console for popup window, run window.close(). The popup refuse to close

The demo app also shows a similar case using window.location.replace which doesn't break window.close().

I also attached video for the demo.

from flask import Flask

app = Flask(name)

@app.route("/")
def index():
return """
<script>
function openPopup1() {
window.open("/popup1", "Popup1", "height=600,width=450,top=100,left=1055");
}
function openPopup2() {
window.open("/popup2", "Popup2", "height=600,width=450,top=100,left=1055");
}
</script>
<button onclick="openPopup1()"> Open popup assign </button>
<button onclick="openPopup2()"> Open popup replace </button>
"""

@app.route("/popup1")
def popup_first():
return (
"<script> assignLocation = () =>"
" {window.location.assign('https://google.com');} </script>"
+ "<button onclick='assignLocation()'>Assign Location</button>"
)

@app.route("/popup2")
def popup_second():
return (
"<script> assignLocation = () =>"
" {window.location.replace('https://google.com');} </script>"
+ "<button onclick='assignLocation()'>Replace Location </button>"
)

Actual results:

Popup window opened by Javascript can't be closed after window.location.assign call.

Expected results:

It should still be closed by window.close() as the window is opened by Javascript. Both Chrome and Safari closes it in such scenario.

Attached file flask-app.py

I included the code in an attachment for better format, and here's the link to the video demo https://youtu.be/ClOqtx6rFGY

The Bugbug bot thinks this bug should belong to the 'Core::DOM: Geolocation' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

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

Confirmed on 117 and 119 Nightly. Attempting to call window.close() from the console gives a "Scripts may not close windows that were not opened by script." warning message and fails to close the popup.

Severity: -- → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: