Retrieving unstable content in Crome extention

59 views
Skip to first unread message

Alex

unread,
Sep 18, 2023, 8:27:23 AM9/18/23
to Chromium Extensions
Hello everyone,

I get content of a downloaded page in Chrome extension. Mostly content is retrieved wholly, but on some pages it returns 39 symbols. And on my observation it doesn't depend on the size of these pages. For instance, I get length of the page https://clockify.me/ in the size of 30475, the page https://clockify.me/time-management-techniques - 39.

manifest.json
{
  "name": "Getting Started Example",
  "description": "Build an Extension!",
  "version": "1.0",
  "manifest_version": 3,
  "permissions": [
    "storage",
    "activeTab",
    "scripting"
  ],
  "action": {
    "default_popup": "popup.html",
    "default_icon": {
      "16": "images/icon-16.png",
      "32": "images/icon-32.png",
      "36": "images/icon-36.png"
    }
  },
  "icons": {
    "16": "images/icon-16.png",
    "32": "images/icon-32.png",
    "36": "images/icon-36.png"
  }
}

popup.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <div id="size"></div>
  <script src="popup.js"></script>
</body>
</html>

popup.js
chrome.runtime.onMessage.addListener(function (request, sender) {
  if (request.action == "getSource") {
    document.getElementById('size').innerHTML = request.source.length;
  }
});
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
  chrome.scripting.executeScript({
    target: { tabId: tabs[0].id, allFrames: true },
    files: ['cscript.js']
  });
});

cscript.js
var s = document.documentElement.outerHTML; 
chrome.runtime.sendMessage({ action: "getSource", source: s });

Patrick Kettner

unread,
Sep 27, 2023, 3:28:47 PM9/27/23
to Alex, Chromium Extensions
Hi Alex
When you say 39 symbols, do you mean the content length of the html response is 39 characters in length? What is specifically in the 39 symbols? Is it possible the query is hitting a different page than you think?

patrick

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/0f96505e-795e-48f4-b3fa-6be75134fa8dn%40chromium.org.
Reply all
Reply to author
Forward
0 new messages