0

I'm trying to build a javascript code that will open a new tab and listen to the URL changes on it. Basically I'm creating a code that needs authentication on a third party app, so I would redirect the user to authenticate to the app, and I would like to listen to the URL redirect there, to close the opened tab and perform the next step on my script.

I'm able to create a new tab with below code:

var newTab = window.open("URL");

I would like to "listen" to this new tab, so when it gets to URL2 (which would be after a successful authentication), I would like to close this tab and progress on my script.

I tried doing so based on below responses, but I couldn't: How to detect url change in a new browser tab and get back the url? Detect tab URL change inside a Firefox add-on SecurityError: Blocked a frame with origin from accessing a cross-origin frame

Any insights?

  • Tabs can't access the URL of other tabs, it's a security risk and against browser privacy protocols. Does this 3rd party store any tokens or anything in local storage when it authenticates? If so you check this answer: https://stackoverflow.com/questions/2236828/javascript-communication-between-tabs-windows-with-same-origin/12514384#12514384 – Jayce444 Mar 17 '21 at 03:01

0 Answers0