-1

Uncaught (in promise) TypeError: Failed to fetch Context popup.html Stack Trace popup.js:10 (anonymous function) "const response = await fetch('http://localhost:5000/process', {"

document.getElementById('keyword-form').addEventListener('submit', async (event) => { event.preventDefault(); const keyword = document.getElementById('keyword').value;

// Define your subreddit names, start_date, and end_date here
const subredditNames = ['AskReddit', 'worldnews', 'gaming'];
const startDate = '2023-04-01';
const endDate = '2023-04-30';

const response = await fetch('http://localhost:5000/process', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    keyword,
    subreddit_names: subredditNames,
    start_date: startDate,
    end_date: endDate
  })
});


const result = await response.json();

// Update the result element with the response from the backend server
document.getElementById('result').innerHTML = JSON.stringify(result);

});

I'm familiar with python. This is my first attempt working with chrome extension

In My original attempts i tried using gstatic to create a chart and chart.js, but both of those ran into issues with the content_security_policy.

1 Answers1

0

The error you have is caused by the 'fetch' request to 'http://localhost:5000/process' not working. To fix it:

Make sure your server is running on 'localhost:5000' and has the '/process' endpoint set up to receive POST requests.

This seems more like the issue is related to the server connection rather than the code itself so make sure your json file is configured to allow the permission and security policies that are required.

{
  "manifest_version": 2,
  "name": "Your Extension Name",
  "version": "1.0",
  "description": "Your Extension Description",
  "permissions": [
    "http://localhost:5000/"
  ],
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
  • 1
    Heres what my manifest.json looks like and I removed the icons because it was too long. { "manifest_version": 3, "name": "Keyword Counter", "version": "1.0", "action": { "default_popup": "popup.html", "default_icon": { } }, "permissions": ["declarativeContent", "tabs"], "host_permissions": ["http://localhost:5000/"], "background": { "service_worker": "background.js" }, "content_security_policy": { "extension_pages": "script-src 'self'; object-src 'self'" } } – Michael Eckert May 02 '23 at 01:52
  • heres the git https://github.com/tipe17311/reddit-keyword-counter – Michael Eckert May 02 '23 at 04:38