<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: gurupetach</title>
    <description>The latest articles on DEV Community by gurupetach (@gurupetach).</description>
    <link>https://dev.to/gurupetach</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F468264%2Fb504b04e-13a6-47ce-8df5-e761eba4d79c.png</url>
      <title>DEV Community: gurupetach</title>
      <link>https://dev.to/gurupetach</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gurupetach"/>
    <language>en</language>
    <item>
      <title>google chrome pdf extension</title>
      <dc:creator>gurupetach</dc:creator>
      <pubDate>Wed, 05 Apr 2023 08:16:03 +0000</pubDate>
      <link>https://dev.to/gurupetach/google-chrome-pdf-extension-15k5</link>
      <guid>https://dev.to/gurupetach/google-chrome-pdf-extension-15k5</guid>
      <description>&lt;p&gt;Am trying to make a google chrome extension that will handle pdf downloads. I want it to send downloaded pdfs  to server. Please help. This is what I have currently done. My manifest.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "name": "PDF333",
    "version": "1.0.1",
    "description": "PDF auto download",
    "manifest_version": 3,
    "author": "Petach",

    "icons": {
        "16":"icons/16.png",
        "32":"icons/32.png",
        "48":"icons/48.png",
        "128":"icons/128.png"
    },
    "permissions": [ "downloads", "activeTab"],
    "background": {
    "service_worker": "background.js"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally background.js as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chrome.downloads.onChanged.addListener(function (downloadDelta) {

    if (downloadDelta.state &amp;amp;&amp;amp; downloadDelta.state.current === "complete" &amp;amp;&amp;amp; downloadDelta.mime === "application/pdf") {
        chrome.downloads.search({ id: downloadDelta.id }, function (downloadItems) {
            var xhr = new XMLHttpRequest();
            xhr.open("POST", "http://localhost:4000");
            xhr.setRequestHeader("Content-Type", "application/pdf");
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        console.log("PDF uploaded successfully!");
                    } else {
                        console.error("Failed to upload PDF.");
                    }
                }
            };
            xhr.send(downloadItems[0].filename);
        });
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>questions</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
