If I understand correctly, you want to get some information contained on the current page into your global page. Unfortunately using document.getElementById('link');
won't work directly, as the global page doesn't have access to the content of web pages (for security reasons, I think).
You will have to use an injected script, and messaging to send the information to the global page. For example, you might do the following:
global.js
const app = safari.application;
app.addEventListener('message', handleMessage, false);
function sendingLink(link) {
app.activeBrowserWindow.activeTab.page.dispatchMessage('getLink');
}
function handleMessage(msg) {
if (msg.name === 'returnLink') {
alert(msg.message);
}
}
injected.js
safari.self.addEventListener('message', handleMessage, false);
function handleMessage(msg) {
if (msg.name === 'getLink') {
// Trigger share button. Maybe:
// document.getElementById('link').click();
var link = document.getElementById('leurl').value;
safari.self.tab.dispatchMessage('returnLink', link);
}
}
Then make sure these are set as the global page and an injected script respectively, in the Safari Extension Builder.
The Apple Safari Extensions Development Guide is a great resource for things like this.