EugeneDae / vscode-refresh-browser

(VS Code extension) Refresh your web-browser with ⌘R without switching from Code. Only works on macOS.
https://marketplace.visualstudio.com/items?itemName=dae.vscode-refresh-browser
MIT License
7 stars 2 forks source link

How to debug an error? #10

Closed halo closed 3 years ago

halo commented 3 years ago

After a couple hours of regular work, this extension stops to refresh the browser. Instead it shows this message:

Screen Shot 2021-09-07 at 19 20 39

I have no idea what causes it. I already tried deactivating pretty much every other extension but the error keeps recurring after some time.

One time I thought that the problem starts happening when I save a file (CMD + s) and then quickly try to refresh the browser. But I cannot reproduce the error.

Is there any log file that could hint me as to what is going wrong?

Thank you for your time and for making this extension, it's very useful.

EugeneDae commented 3 years ago

Is there any log file that could hint me as to what is going wrong?

Yes, please try: Screen Shot 2021-09-08 at 01 25 24

Then switch to Console:

Screen Shot 2021-09-08 at 01 25 46

Thanks!

EugeneDae commented 3 years ago

Another thing to try is to run the AppleScript code without the extension.

  1. Using Spotlight, find Script Editor.app.
  2. Paste the code from below.
  3. Script > Run.
  4. See if it works and if there are any errors or warnings.
set URL_PREFIXES to {"https://localhost"}

tell application "Google Chrome"
    set _wIndex to 0
    set _tIndex to 0
    set _target to active tab of front window

    if ((count of URL_PREFIXES) > 0) then
        repeat with _window in windows
            set _wIndex to _wIndex + 1
            repeat with _tab in tabs of _window
                set _tIndex to _tIndex + 1

                if (my startswith(URL of _tab, URL_PREFIXES)) then
                    set _target to _tab
                    set active tab index of window _wIndex to _tIndex
                    exit repeat
                end if
            end repeat
        end repeat
    end if

    reload _target
end tell

on startswith(_str, _list)
    repeat with i in _list
        if _str starts with i then return true
    end repeat
    false
end startswith
halo commented 3 years ago

Ok, thanks a lot for leading the way :)

It's the Apple Script failing when trying to access front window of Google Chrome

Screen Shot 2021-09-08 at 08 51 04

I tried to debug it but. Apple Script says Chrome is running and that it is active, but it simply has no windows.

Screen Shot 2021-09-08 at 08 56 01

I also tried to wait for it but the window would never exist:

Screen Shot 2021-09-08 at 08 45 06

So I thought that the Google Chrome process must have run an automatic update of itself and maybe the OS can't access it any more. I quit Chrome - and I could not restart Chrome. I had to manually kill every helper and renderer process that was related to Chrome. Then I started Chrome again, and the script works again:

Screen Shot 2021-09-08 at 08 56 05

So – at least I know now that I don't need to restart my computer but that I have a work-around 😆

It would be great, of course, if your extension could display the error message in a more prominent way, and maybe even explain what could have happened.

I almost just deleted the extension because I felt it was buggy. I'm glad I reached out to you, but it would be a shame if other people just delete it and think of it no more.

Again, thank you for your time and effort. I appreciate it.

EugeneDae commented 3 years ago

Nice investigation! So, it's a Chrome's quirk.

It would be great, of course, if your extension could display the error message in a more prominent way, and maybe even explain what could have happened.

Done & published in version 1.1.3.

Thanks!

halo commented 3 years ago

Sweet! Thank you!

I even got the pleasure to try it right away, because Chrome let me down again 😄 and it works:

Screen Shot 2021-09-08 at 21 14 06