実現したいこと
・FlaskとChrome拡張を使って小規模フィルタリングシステムを構築したい
前提
サイトブロックシステムをChromeの拡張機能とFlaskの判定サーバーで作っています。
URLを拡張からJavascripからGETを送ってFlaskの判定サーバーでreturnを使ってAllowかNoAllowを返しています。ですが、CROSの関係でjavascriptからGETリクエストを遅れません。送れるようになるスクリプトを教えてください。
発生している問題・エラーメッセージ
Access to XMLHttpRequest at 'http://127.0.0.1/?url=<exmaple.com>' from origin 'exmaple.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
該当のソースコード
Flask判定サーバー側(Python)
1from flask import Flask, request 2from flask_cors import CORS 3 4app = Flask(__name__) 5CORS(app) 6 7@app.route('/', methods=["GET"]) 8def filtering(): 9 URL = request.args.get('url') 10 if 'google.com' == URL: 11 print("NoAllow") 12 return 'NoAllow' 13 else: 14 print("Allow") 15 return 'Allow' 16app.run(port="80", host="0.0.0.0",)
Chrome拡張機能
1const BlockSite = chrome.runtime.getURL("message-page.html"); 2var URL = "" 3URL = location.host; 4 5var data_url = new XMLHttpRequest(); 6 7data_url.open('GET', 'http://127.0.0.1/?url=' + URL); 8data_url.withCredentials = true; 9data_url.setRequestHeader("Access-Control-Allow-Origin", "http://127.0.0.1"); 10data_url.send(); 11data_url.onreadystatechange = function() { 12 if(data_url.readyState === 4 && data_url.status === 200) { 13 console.log(data_url.responseText); 14 } 15}
試したこと
setRequestHeaderにAccsess-Control-Allow-Originをつけた
→改善せず
ajaxを使って構築しようとした
→分からなくて挫折した
補足情報(FW/ツールのバージョンなど)
環境はすべてローカルで動かしています。

回答2件
あなたの回答
tips
プレビュー