!!Question edited
Sorry for my english. I hope you can help me. Thank you
I'm making a google chrome extension . the purpose of the application:
Clicking on the Chrome extension will take the price of the product on the current site. Then it will post this price to a site prepared with php.
Code:
manifest.json
{
"name": "get current html of page ",
"version": "1.0",
"manifest_version": 3,
"description": "my first extension",
"action": {
"default_icon": "icon.png"
},
"permissions": ["activeTab", "scripting"],
"host_permissions":[
"https://*/",
"http://*/",
"https://yaziciemre.com/",
"http://localhost/*/",
"http://www.google.com/*"
],
"background": {
"service_worker": "background.js"
}
}
popup.html
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="index.css">
<script type="text/javascript" src="background.js"></script>
</head>
<body>
</body>
</html>
background.js
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["parse_page.js"],
});
const xhr=new XMLHttpRequest();
const baseurl="https://yaziciemre.com/ip.php";
xhr.open("POST",baseurl,true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
let data=ps1;
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
console.log(xhr.responseText);
}
}
xhr.send(JSON.stringify({ "price": data }));
});
parse_page.js
var ps1 = document.getElementsByClassName('s1wl91l5-4 cBVHJG')[0].innerHTML;
window.alert(ps1);
I store the price of the product on the current site in a variable but I can't post this price to a site created with php The url of the site I want to post the price of: https://yaziciemre.com/ip.php
When I click on the chrome extension, I can get the price and keep it in a variable. how can i post this price?
please click the picture
[1]: https://i.stack.imgur.com/c3EgH.png