Reputation: 5059
I need to make GET http calls to ‘http://localhost:3000/posts’ from a dev chrome page action extension. With the GET action I get a list of posts which need to be displayed in popup.html. In ‘content.js’ I fetch a list of topics from current tab to pass as a query parameter in GET request.
Upvotes: 1
Views: 7946
Reputation: 3783
Since chrome extension is just a html/css/js - to make web requests you can use the same techniques as you do on normal websites. E.g. fetch api or XHR.
From where to call depends only from you. If you want to cache the results background page might be better, but then you would need to use messaging to transfer data from background page to popup page. Otherwise you can call your api right from the popup script.
Anyway you might have problems with CORS when working with api hosted on localhost (it is a known chrome limitation). With normal page you can use one of many extensions that automatically add CORS headers to all requests, but I'm not sure they would work with requests from extensions.
Upvotes: 5