0

I am trying to do the below

  fetch("https://www.google.com/search?q=trees&tbm=isch&sxsrf=ALiCzsYCq08DI1a2kANT5mYBvDyYi7keWw%3A1671527330860&source=hp&biw=2025&bih=1279&ei=onuhY7uXMcaA0PEP6t2GuAo&iflsig=AJiK0e8AAAAAY6GJshVTus5cslLxfh_vqy0n5ro5Half&ved=0ahUKEwi78KPG7If8AhVGADQIHequAacQ4dUDCAc&uact=5&oq=trees&gs_lcp=CgNpbWcQAzIICAAQgAQQsQMyCAgAEIAEELEDMggIABCABBCxAzIFCAAQgAQyBQgAEIAEMggIABCABBCxAzIICAAQgAQQsQMyCAgAEIAEELEDMgUIABCABDIFCAAQgAQ6BAgjECc6CAgAELEDEIMBOgsIABCABBCxAxCDAToHCCMQ6gIQJzoFCAAQsQNQAFibFmD8FmgDcAB4AIABN4gBkAOSAQE4mAEAoAEBqgELZ3dzLXdpei1pbWewAQo&sclient=img", {
    
  })
  .then(response => {
      console.log(response)
  })

but this is giving me errors

Access to fetch at 'URL' from origin 'chrome-extension://...' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I have tried using headers with 'Access-Control-Allow-Origin' but this still return the same error. I have also tried using 'no-cors'. This works but then there is no body returned and I need the HTML for parcing.

I also have the below but it did not fix the issue.

"host_permissions": [
    "https://www.website.com/*"
  ],
  • Why do people always get this backwards? That header is sent by the server, not the client. – Barmar Dec 20 '22 at 09:14
  • See https://developer.chrome.com/docs/extensions/mv3/xhr/ – Barmar Dec 20 '22 at 09:16
  • 1
    [^](https://stackoverflow.com/questions/74860744/how-do-i-fetch-a-the-html-of-a-website-within-a-chrome-extension#comment132113144_74860744) "_Why do people always get this backwards?_" @Barmar I think it's simply "I'm aware that this is one variable involved in the scenario, so I tried to make a change that relates to it to see if my code might work" rather than intentional research to understand: analogous to toggling random settings to see which combination might work. – jsejcksn Dec 20 '22 at 09:21
  • Nope adding the website to host_permissions still had the same issue. "host_permissions": [ "https://www.website.com/*" ], – Philip Phil Dec 20 '22 at 20:28

0 Answers0