manifest.json:
{
"name": "setence break down py",
"version": "0.1.0",
"description": "Destrinchar sentenças gramaticalmente",
"permissions": ["tabs", "activeTab", "contextMenus", "webRequest", "storage"],
"host_permissions": ["<all_urls>"],
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["contentScript.js"]
}
],
"action": {
"default_popup": "breakdown.html",
"default_title": "sentence breakdown"
},
"manifest_version": 3
}
background.js:
/*const { OpenAI } = require('openai');*/
chrome.runtime.onInstalled.addListener(function() {
chrome.contextMenus.create({
id: "acionarpy",
title: "acionarpy",
contexts: ["selection"]
});
});
var selecao
chrome.contextMenus.onClicked.addListener(function(info, tab) {
selecao = info.selectionText
if (info.menuItemId === "acionarpy") {
chrome.windows.create({
type: "popup",
url: "breakdown.html",
width: 300,
height: 200
});
}
});
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
if (message.action === "janelaCriada") {
console.log("menssagem")
console.log(selecao)
sendResponse({
resposta: selecao
})
}
});
contentScript.js:
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
if (message.action === "janelaCriada") {
console.log( window.getSelection().toString())
sendResponse({
resposta: "cs"
})
}
});
breakdown.html:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>breakdown</title>
</head>
<body>
<!--<main class="container-fluid py-5 text-center">
{% block main %}{% endblock %}
</main>-->
<div>
<h2>Texto selecionado: </h2>
<p id="selectedText">-</p>
</div>
<form name="call" id="call" action="/call" method="post">
<input type="text" value="">
</form>
<div>
<p id="tg">+</p>
</div>
<script src="breakdown.js"></script>
</body>
</html>
breakdown.js:
var texto
window.onload = function() {
console.log("breakdown");
chrome.runtime.sendMessage({action: "janelaCriada"}, async function(response){
console.log("menssagem no breakdown:")
console.log(response.resposta)
texto = response.resposta
console.log("texto:", texto)
document.getElementById("selectedText").textContent = response.resposta
document.querySelector('input[type="text"]').value = response.resposta
document.call.submit();
});
};
teste.py:
from flask import Flask, flash, redirect, render_template, request, session, g
from flask_session import Session
import os
import google.generativeai as genai
app = Flask(__name__)
@app.route("/call", methods=["GET", "POST"])
def api_call():
if request.method == 'POST':
call_prompt = request.form.get("call")
print(call_prompt)
return None
if __name__ == '__main__':
app.run()
this is what the popup console looks like:
menssagem
background.js:29 trouble
(index):3156 crbug/1173575, non-JS module files deprecated.
(anonymous) @ (index):3156
why is this error happening?
I wanted to send the form value to the flask app (i’m planning to do something else with this value in there), and print it, so i could test the value update