Chrome identity API spotify oauth2 login

Tags: , , ,

I’m trying to implement spotify login in my chrome extension but I get always this error and I’m able to see the auth window only when the browser is loaded for the first time.

Unchecked runtime.lastError: Authorization page could not be loaded.

This is the code I’m using

const client_id = '<client_id>'
const redirectUri = chrome.identity.getRedirectURL('spotify');


chrome.runtime.onMessage.addListener( (message, sender, sendResponse) => {
  if( message.action === 'run_auth_flow' ){
      "url": `${client_id}&redirect_uri=${redirectUri}&response_type=token`, 
      'interactive': true,  
    }, (redirect_url) => { 
  //sendResponse({ status: 'ok' })
  return true;

chrome.identity.onSignInChanged.addListener( (account, signedIn) => {
  console.log(account, signedIn)

Is there any fix? I just want to access the spotify API to play users playlist in my chrome ext


The problem with the auth flow was in this line of code:

const redirectUri = chrome.identity.getRedirectURL('spotify');

To make things working I’ve just used getRedirectURL() without passing any path.

const redirectUri = chrome.identity.getRedirectURL();

This will give back a virtual url address like this https://<app-id> in the callback with the auth token appended to it.

Source: stackoverflow