get tab url return always undefined [duplicate] - javascript

This question already has answers here:
How to open the correct devtools console to see output from an extension script?
(3 answers)
How can I get the URL of the current tab from a Google Chrome extension?
(11 answers)
Closed 2 years ago.
I have an extension that will work only on a given url and I'm using the declarativeContent api to achieve this. When the extension icon is clicked a new popup window that will hold the popup.html will be opened.
I need a way to get the url of the tab that have opened the popup from the popup.js file, I've with chrome.tabs.query but I will get always undefined. Is there a better way?
chrome.tabs.query({
active: true,
lastFocusedWindow: true,
url: 'https://example.com/*' }, (tab) =>{
console.log(tab) // undefined
})

Related

chrome extension get popup window object from popup file [duplicate]

This question already has answers here:
How to access the webpage DOM/HTML from an extension popup or background script?
(2 answers)
Access global js variables from js injected by a chrome extension
(1 answer)
Closed 5 days ago.
I want to get window object of current tab from popup.js but I can't find a way to do that. i keep getting the popup's window object
I tried just accessing window but it got the popup's window
You need to filter window Types
Doc link method-getLastFocused
chrome.windows.getLastFocused({ windowTypes: ["normal"] }, (win) => console.log(win));

window.open is opening a new tab with orgin/url [duplicate]

This question already has answers here:
window.open() simply adds the url to my current url
(4 answers)
Closed 4 years ago.
I have a button that is located inside iframe with url="loclahost:3000" for example.
I have an event on this button that should open a new tab with another url for example "www.google.com". But when I click the button I am getting the new tab opened with the following url "http://localhost:3000/www.google.com"
I am using a window.open('www.google.com") function in order to open the new tab.
How can I remove the "http://localhost:3000/" from the new tab url?
The best way to do so would be to use an absolute link, which cancels out any relativity the URL might have:
var url = "https://www.google.com";
window.open(url);
Here the https:// signifies it's a completely different page to the current page, so the browser should open that link, not try and find a file by that name.

Can't open chrome://something with window.open on Chrome [duplicate]

This question already has answers here:
Link to chrome:// url from a webpage
(2 answers)
How to open a page with information about the browser?
(2 answers)
Closed 4 months ago.
Good evening everyone,
I would like to open a window with javascript code.
Usually window.open works fine but the link I provide is chrome://gpu and when I do that, Chrome redirects me to the about:blank page. It happens only with chrome:// links, everything else works fine.
I may understand it is some security issue and Chrome blocks these links to be opened. Do you know if there is a workaround or a setting to allow Javascript to open chrome:// in a new window ?
Thanks a lot,
Clems4ever

Why is my URL called in JavaScript opening as pop-up [duplicate]

This question already has answers here:
Open a URL in a new tab (and not a new window)
(33 answers)
Closed 8 years ago.
Browser settings vary for allowing popups and I want my URL which is called within a JavaScript function to open in a new tab and not be considered a popup.I am opening the url as:
window.open(my_global_link,'_blank');
In IE and FireFox, when I click on the image I get a notification Pop-up blocked and only by Allowing pop-up for the site the URL would open in a separate tab. How can I make it open in a separate tab and not consider it a pop-up?
It is a browser setting . try finding navigation options for new tabs in the browser you are using and set it to open in a new tab instead off a new window.

Javascript: Change Url without refreshing the page [duplicate]

This question already has answers here:
How do I modify the URL without reloading the page?
(20 answers)
Closed 8 years ago.
I am in a page with url
https://mysite.com/tst/v1/my-app/var/$%5Btest_new_var%5D.
On click i want to change the url to
https://mysite.com/tst/v1/my-app/" without reloading the page.
How can i do that?
please help,
Thanks.
In newer browsers that support history.pushState you can replace the url without reloading.
Lets say a user browses to http://example.com/ernie.html
window.history.pushState({ foo: "bar" }, "page 2", "bert.html");
Will change the address bar to http://example.com/bert.html, but won't cause the browser to load bert.html or even check that bert.html exists.

Categories