Safari extension: how to get current url from injected script?

396 views Asked by At

I am trying to get the current url from injected script but it seems impossible because of the permission. From the official document, I got:

Injected scripts cannot access the SafariApplication or SafariExtension classes.

Is there any solution or w/a? Thanks.

1

There are 1 answers

2
Matt Swain On

Use window.location.href to get the URL of the page the script is injected into.

Scripts are injected into each iframe as well as the main page, so you might want to use a check like if (window == window.top) to if you are only interested in the main page.