Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
993 B
3
Indexable
Never
const handleScrape = async () => {
  try {
    const tabs = await new Promise<chrome.tabs.Tab[]>((resolve, reject) => {
      chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
        if (chrome.runtime.lastError) {
          return reject(chrome.runtime.lastError);
        }
        resolve(tabs);
      });
    });

    if (tabs.length > 0 && tabs[0].id !== undefined) {
      const response = await new Promise<any>((resolve, reject) => {
        chrome.tabs.sendMessage(
          tabs[0].id!,
          { action: "getProfileData" },
          (response) => {
            if (chrome.runtime.lastError) {
              return reject(chrome.runtime.lastError);
            }
            resolve(response);
          }
        );
      });

      console.log(response);
      if (response) {
        if (response === "invalid adress") return;
        setScrapingResult(response);
      }
    }
  } catch (error) {
    console.error("Error during scraping", error);
  }
};
Leave a Comment