The content of the script is linked to the bg page [Synchronous]

Howdy, well, I know that the script content can link to the man page using:

chrome.extension.sendRequest({action:'test'}, function(response) { //code here... }); someFunction(); 

But is it possible to communicate synchronously? Basically wait until the response returns to the contents of the script before executing someFunction ()?

If not, is it possible to link to the bg page using regular xmlhttprequest?

Why do you ask?

I upload my script content to the document_start webpage (required), and one of my variables in CS depends on the localStorage variable set on the options page. Therefore, I need this localStorage variable from the background page to calling the Function () function.

Thanks in advance.

+4
source share
1 answer

You can bind callbacks to call the next query.

or

You can explicitly specify XHR as synchronous.

 chrome.extension.sendRequest({action:'test'}, function(response) { someFunction(response); // Calling the function // or chrome.extension.sendRequest(...); }); function someFunction (resp) { // Execute code }; 
+1
source

Source: https://habr.com/ru/post/1316573/


All Articles