How to get URL of active tab from popup.js with Safari iOS App Extension in iOS 15?

I'm developing Safari App Extension for iOS 15.0+ and I need to get URL of active tab in popup.js and display.

Here is how I do that in popup.js:

document.getElementById("activetaburl").innerHTML = document.URL

As result it returns path of current popup.js

Here is my permissions from manifest.json:

"permissions": ["nativeMessaging", "activeTab"]

And info.plist:

<dict>
	<key>NSExtension</key>
	<dict>
		<key>NSExtensionAttributes</key>
		<dict>
			<key>NSExtensionActivationRule</key>
			<dict>		<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
				<integer>1</integer>		<key>NSExtensionActivationSupportsImageWithMaxCount</key>
				<integer>10</integer>
			</dict>
		</dict>
		<key>NSExtensionPointIdentifier</key>
		<string>com.apple.Safari.web-extension</string>
		<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).SafariWebExtensionHandler</string>
	</dict>
</dict>

So how to fix the issue above and get url of active tab?

Thanks, Serge

You can get the current URL with this code:

browser.tabs.getSelected(null, function(tab) {
    document.getElementById("activetaburl").innerHTML = tab.url;
});

Did that suggestion work for you?

How to get URL of active tab from popup.js with Safari iOS App Extension in iOS 15?
 
 
Q