Jump to content

Recommended Posts

Posted (edited)

Today I found this:

https://github.com/gildas-lormeau/SingleFile/discussions/1226

I tried to use this with GoogleChrome

https://chrome.google.com/webstore/detail/singlefile/mpiodijhokgodhhofbcjdecpffjipkle

 

I found some solution here:

https://stackoverflow.com/a/75376708/5314940

And I'm trying to do it this way:

function send(extensionId, msg, callback, retry = 20) {
  const timer = setTimeout(send, 100, extensionId, msg, callback, retry - 1);
  chrome.runtime.sendMessage(extensionId, msg, response => {
    if (!chrome.runtime.lastError || !retry) {
      clearTimeout(timer);
      callback(response);
    }
  });
};
send('{531906d3-e22f-4a6c-a102-8057b88a1a63}', '{ action: "save-page" }');

 

But errors occurs.
Any help with how to use it with JS ?

EIDT:
After finding a way I provide example in AutoIt

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Yes, it is continuation. You asked me to be more specific in my question.
So here we are with this new topic, as for now only related to JS, but ultimately it will be used with au3WebDriver UDF.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 8/24/2023 at 7:26 PM, mLipok said:

And I'm trying to do it this way:

function send(extensionId, msg, callback, retry = 20) {
  const timer = setTimeout(send, 100, extensionId, msg, callback, retry - 1);
  chrome.runtime.sendMessage(extensionId, msg, response => {
    if (!chrome.runtime.lastError || !retry) {
      clearTimeout(timer);
      callback(response);
    }
  });
};
send('{531906d3-e22f-4a6c-a102-8057b88a1a63}', '{ action: "save-page" }');

 

But errors occurs.

Expand  

hmm..... 

I think I understand.
This can only be used in EXTENSION code.
This cannot be used directly in JS.

Please verify my reasoning.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

  So w need to stick with this solution:

  On 7/20/2023 at 9:44 PM, mLipok said:
Expand  

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 8/25/2023 at 12:50 PM, Danp2 said:

Why not?

Expand  

a guess.

for this reason I said

  On 8/25/2023 at 8:49 AM, mLipok said:

Please verify my reasoning.

Expand  

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 8/25/2023 at 12:50 PM, Danp2 said:

Edit: Have you tried the method discussed here?

Expand  

interesting... but still the same.

more searching and:

https://stackoverflow.com/questions/27207129/why-is-chrome-runtime-undefined-when-running-js-inside-a-page-from-a-content-scr

  Quote

If you're inserting JavaScript into a page with a <script> tag, it executes in the page's context.

Sometimes it is desirable: that's the only way to access page-level JavaScript objects.

But in your case it means that the code does not have access to Chrome APIs, as it is "the same" as the page's code.

You need to look into communicating between page-level and content scripts, or between page-level and background (spoiler, in most cases needs a context script proxy anyway).

Expand  

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

So after I read this: https://stackoverflow.com/a/26740141/5314940

 

my next test was:

function send(extensionId, msg, callback, retry = 20) {
  const timer = setTimeout(send, 100, extensionId, msg, callback, retry - 1);
  chrome.runtime.sendMessage(extensionId, msg, response => {
    if (!chrome.runtime.lastError || !retry) {
      clearTimeout(timer);
      callback(response);
    }
  });
};

// Content script
// Listen for the event
window.addEventListener("FromPage", function(evt) {
    console.log('test')
  send('{531906d3-e22f-4a6c-a102-8057b88a1a63}', '{ action: "save-page" }');
}, false);

// Page context
var message = {/* whatever */};
var event = new CustomEvent("FromPage", {detail: message});
window.dispatchEvent(event);

Still no success.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 8/25/2023 at 3:59 PM, Danp2 said:

How are you testing (manually in the browser's dev console or via a WD script)?

Expand  

manually in the browser's dev console

EDIT: via WD script will be tested in next step ;)

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 8/25/2023 at 4:46 PM, Danp2 said:

My guess is that it won't work via WD if you can't make it work manually in the dev console.

Expand  

for this reason firstly we need make it work manually in the dev console

And this is what I'm asking here.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

simple solution (on win7):
navigate to page you want to save as mht
wait until the page visible
then send Ctrl+s

func __SaveAs_MHT()
    Send("^s")
    WinWait("[Title:Save As]")
    Local $hWnd = WinGetHandle("[Title:Save As]")
    ControlSend($hWnd, "", "Edit1", "This is some text")
    ControlCommand($hWnd, "", "ComboBox2", "SelectString", "Webpage, Single File")
    ;....
EndFunc

 

Edited by jugador
Posted

This is not the same. Your solution will not product correct MTH file - I mean not with all required content which always looks like oryginal.

I need to use SingleFile extension or SavePageWE extension.
As far as I was able to findout only SingleFile extension have API to call them from other programs.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 8/25/2023 at 8:49 AM, mLipok said:
531906d3-e22f-4a6c-a102-8057b88a1a63
Expand  

FWIW, this appears to be the extension ID for FF, not Chrome. The correct one AFAICS is "mpiodijhokgodhhofbcjdecpffjipkle". Based upon what I found here, I would have thought that the following would trigger it.

chrome.runtime.sendMessage('mpiodijhokgodhhofbcjdecpffjipkle', "save-page")

Unfortunately, no such luck. No errors, but no saved file AFAICS.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...