maximilian
(Maximilian)
September 5, 2015, 6:14am
1
I am trying to access the urlbar from addon sdk and cannot get it to work.
This is what I am doing:
var { viewFor } = require("sdk/view/core");
var tab_utils = require("sdk/tabs/utils");
var getBrowser = function(tab) {
return tab_utils.getBrowserForTab(viewFor(tab));
}
tabs.on('ready', function (tab) {
var worker = tab.attach({
contentScriptFile: data.url('back.js')
});
var browser = getBrowser(tab);
console.log(browser.contentWindow.document.getElementById('urlbar'));
});
And it always returns null. What am I doing wrong?
noitidart
(Noitidart)
September 5, 2015, 6:27am
2
Try getBrowser(tab).defaultView.gURLBar
You are tapping into the window of the website in the tab, and that doesn’t have a URL bar, the url bar is apart of the “browser chrome window”, not the “tab content window”.
I use gURLBar here:
}
// START - Addon Functionalities
function showTip(aEvent) {
var cDOMWindow = aEvent.view;
var popup = cDOMWindow.document.getElementById('awesomebar-power-tip_panel');
var cHidePop = function(aEvent) {
//cDOMWindow.clearTimeout(timeoutHide);
cDOMWindow.gURLBar.removeEventListener('blur', cHidePop, false);
cDOMWindow.gURLBar.removeEventListener('keypress', cHidePop, false);
popup.hidePopup();
};
popup.openPopup(cDOMWindow.gURLBar, 'after_start', 30, 0, false, false);
//var timeoutHide = cDOMWindow.setTimeout(cHidePop, 6000);
cDOMWindow.gURLBar.addEventListener('blur', cHidePop, false);
cDOMWindow.gURLBar.addEventListener('keypress', cHidePop, false);
var prefs = {};