1

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.

7
  • provided you're not getting blocked due to cross-origin denial, start with 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. Commented Jan 15, 2020 at 4:40
  • 1
    fetch followed by DOMParser looks like it should do the trick Commented Jan 15, 2020 at 4:42
  • @Mike'Pomax'Kamermans Edited the question -- didn't include that I was indeed getting a cross-origin denial. Commented Jan 15, 2020 at 4:45
  • 1
    @Mike'Pomax'Kamermans .then(result => result.blob()).then(blob => blob.text()) really? Why don't you consume that response as text directly? Commented Jan 15, 2020 at 4:46
  • @Kiwon Yun It sounds like you're looking for Product Advertising API for Amazon. There's some hurdles to jump over to get access to it. The Product Advertising API is available to Associates that have been reviewed and received final acceptance into the Associates Program. The first step is for you to make three qualifying sales through your links. After this is done your account will be reviewed by a specialist. Have you considered using Google Books API? Commented Jan 15, 2020 at 4:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.