I am trying to build a chrome extension that takes a highlighted text (the use case is going to be books), searches for that text on Amazon, and auto-populates a corresponding title, book cover, and its author on the Chrome Extension popup window.
So far, I have been successful in passing the highlighted variable from the script file to the popup.js file. The question is this: is it possible for me to request a search result page, then run the typical querySelector methods to create an array of the necessary information, all without opening the window itself?
var searchLink = 'https://www.amazon.com/s?k=' + highlightedText
fetch(searchLink){
// target a certain class/id and return an array of information
Very new to JS, so apologies if this is a foolish question. I am getting a cross-origin denial when I try this in my browser console. Is this something that requires an Amazon affiliate/developer API? Thanks in advance.
fetch("https://......").then(result => result.blob()).then(blob => blob.text()).then(text => console.log(text)).catch(e => console.error(e));. With that page source, I'm sure you can now use google etc. to figure out how to turn that into a separate document that you can run query selectors on.fetchfollowed byDOMParserlooks like it should do the trick.then(result => result.blob()).then(blob => blob.text())really? Why don't you consume that response as text directly?