I'm trying to understand if it's feasable to open, for a user, an external ecommerce website and fill the cart instead of him with specific products (that the user selected on my website).
Up to now the following possible solutions came to my mind:
- Extension: the user download an extension, when he click on a button on the extension a new tab with the external ecommerce is opened, then a injected javascript script autocompile the cart (automating the clicks that lead to the "add to cart button")
- iFrame: it is the same of the above solution, but I was wondering if with an iFrame I could achieve the same thing I can achieve with an extension
Of the two solutions I'd prefer the second one, mostly because an extension could not be used in a mobile browser. However I'm wondering if there is some other faster solution client side (for example could an application make the automation process simpler?). Right now I implemented a very basic script for the extension solution:
Keep in mind that the wait will be sobstituted with a check of the loading status of the page or something like that
productList.forEach(product => {
chrome.scripting.executeScript(
{
target: {tabId: tabs[0].id},
func: loadProductPage,
args: [product]
}
);
wait(2000);
chrome.scripting.executeScript(
{
target: {tabId: tabs[0].id},
func: addToCart
}
);
wait(1000);
})
wait(1000);
chrome.scripting.executeScript(
{
target: {tabId: tabs[0].id},
func: openCart
}
);
})
function loadProductPage(productUri){
window.location.assign(productUri);
}
function addToCart() {
document.getElementById("button-cart-add").click();
}
function openCart() {
document.getElementsByClassName("icon-cart")[0].click();
document.getElementsByClassName("cart-footer")[0].children[0].click();
}
I realize that is kind of a strange request, I'm a bit lost even on what to search online. It's like a web automation task but I only found things related to web testing or web crawling but not something in order to automate the actions of a user