Answer the question
In order to leave comments, you need to log in
How to make a cross-domain ajax request in chrome extensions (chrome extension)?
Hello!
I'm writing an extension for the Chrome browser.
What is the point: there is a parser that checks new letters in Ya.Mail and sends them to be voiced by a smart column with Alice.
(chrome.tabs):
.get
параметром передаётся текст. На этом сайте ещё 1 мой js юзерскрипт уже делает (подделывает) запрос к колонке и она зачитывает переданный текст. После этого неактивная вкладка закрывается. Answer the question
In order to leave comments, you need to log in
In browser extensions, there are not only user scripts, but also the so-called background page or background script (the same thing). This is like a hidden tab of the extension itself, which is always active while the extension is active. In this tab, right in js, you can store everything that is needed for the extension to work, as well as perform tasks that affect the extension as a whole. For example, you can do ajax to any domains.
To make an ajax request to a domain from a background page, the extension must have rights to that domain. An extreme option is to set the extension rights to any domains, but users do not really like this, because. the extension can potentially steal valuable data from the user's personal tabs, and if there are no rights, then in any case it will not be able to.
You can give permissions in the manifest. This is how the rights to all sites look like (plus tabs):
"permissions": [
"<all_urls>", "tabs"
],
"permissions": [
"https://toster.ru/*", "https://habr.com/*", "notifications", "storage"
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question