[GH-ISSUE #658] Redirect page does not automatically close. #391

Closed
opened 2026-02-27 23:22:22 +03:00 by kerem · 1 comment
Owner

Originally created by @MartijnVogelaar on GitHub (Mar 22, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/658

Describe the bug
Using the oath2 module the user is eventually redirected to the redirect page which should close automatically or should be closed by a click on a button. It however does not work and throws the following error in the browser's console:

Scripts may not close windows that were not opened by script.

In the following piece of code: github.com/plamere/spotipy@dc89a00113/spotipy/oauth2.py (L1282-L1293)
the page tries to close itself by doing a window.close() on line 1282 and also tries to add a button on line 1292 which should close the current window, but it does not.
This is the case in both Chromium-based browsers as in Firefox see: firefox definition .

This behavior is confusing for some users, someone opened an issue on my project regarding this: https://github.com/MartijnVogelaar/krunner-spotify/issues/26

``

Your code

from spotipy.oauth2 import SpotifyOAuth
from spotipy.oauth2 import SpotifyPKCE
import spotipy

CLIENT_ID = "4308514e1497441b9da05278342b8289"
REDIRECT_URI = "http://localhost:8888/callback"

auth_manager = SpotifyPKCE(client_id=CLIENT_ID,
                                redirect_uri=REDIRECT_URI,
                                scope="user-modify-playback-state")
spotify = spotipy.Spotify(auth_manager=auth_manager)
spotify.volume(0)

Expected behavior
The expected result is obviously that the window is automatically closed, or closed by clicking the button.

Output
As said earlier the browser console outputs:

Scripts may not close windows that were not opened by script.

Environment:

  • OS: Kubuntu 20.0.4 / Manjaro KDE
  • Python version: 3.8.5
  • Spotipy version: 2.17.1

Suggestion

I would suggest to just remove the entire button and tell the user that the window can be closed by the user.

Originally created by @MartijnVogelaar on GitHub (Mar 22, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/658 **Describe the bug** Using the oath2 module the user is eventually redirected to the redirect page which should close automatically or should be closed by a click on a button. It however does not work and throws the following error in the browser's console: > Scripts may not close windows that were not opened by script. In the following piece of code: https://github.com/plamere/spotipy/blob/dc89a00113e98b26b4932b582cb4f7b4449fcd4d/spotipy/oauth2.py#L1282-L1293 the page tries to close itself by doing a window.close() on line 1282 and also tries to add a button on line 1292 which should close the current window, but it does not. This is the case in both Chromium-based browsers as in Firefox see: [firefox definition ](https://developer.mozilla.org/en-US/docs/Web/API/Window/close#Description). This behavior is confusing for some users, someone opened an issue on my project regarding this: https://github.com/MartijnVogelaar/krunner-spotify/issues/26 `` **Your code** ``` from spotipy.oauth2 import SpotifyOAuth from spotipy.oauth2 import SpotifyPKCE import spotipy CLIENT_ID = "4308514e1497441b9da05278342b8289" REDIRECT_URI = "http://localhost:8888/callback" auth_manager = SpotifyPKCE(client_id=CLIENT_ID, redirect_uri=REDIRECT_URI, scope="user-modify-playback-state") spotify = spotipy.Spotify(auth_manager=auth_manager) spotify.volume(0) ``` **Expected behavior** The expected result is obviously that the window is automatically closed, or closed by clicking the button. **Output** As said earlier the browser console outputs: > > Scripts may not close windows that were not opened by script. **Environment:** - OS: Kubuntu 20.0.4 / Manjaro KDE - Python version: 3.8.5 - Spotipy version: 2.17.1 **Suggestion** I would suggest to just remove the entire button and tell the user that the window can be closed by the user.
kerem 2026-02-27 23:22:22 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@dieser-niko commented on GitHub (May 1, 2024):

Closing as there's no activity (and also it seems to be fixed).

<!-- gh-comment-id:2089065313 --> @dieser-niko commented on GitHub (May 1, 2024): Closing as there's no activity (and also it seems to be fixed).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#391
No description provided.