Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigate Event Handler does not catch latest URL #31

Open
raphaelheinz opened this issue Mar 24, 2024 · 8 comments
Open

Navigate Event Handler does not catch latest URL #31

raphaelheinz opened this issue Mar 24, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@raphaelheinz
Copy link
Owner

Describe the bug
The navigate event handler does not catch the latest URL but the previous URL. It is always exactly one click behind. Sometimes this leads to push the wrong submission to GitHub. It seems that the event handler is called before the actual link is changed 🤔

LeetCodeV2.prototype.addUrlChangeListener = function () {
window.navigation.addEventListener('navigate', event => {
const problem = window.location.href.match(/leetcode.com\/problems\/(.*)\/submissions/);
const submissionId = window.location.href.match(/\/(\d+)(\/|\?|$)/);
if(problem && problem.length > 1 && submissionId && submissionId.length > 1){
chrome.storage.local.set({ [problem[1]]: submissionId[1] });
}
})
};

To Reproduce
Steps to reproduce the behavior:

  1. Add console.log() to track the window.location.href value.
  2. Switch between different tabs, submissions, ...
  3. Check console.log() messages. They will be exactly one click behind.

Expected behavior
The event listener should somehow access the latest URL instead of the previous URL.

Additional
This issue may be responsible for #29.

@raphaelheinz raphaelheinz added the bug Something isn't working label Mar 24, 2024
@raphaelheinz
Copy link
Owner Author

@itsluminous Do you have an idea what we could try?

@itsluminous
Copy link
Contributor

The UrlChangeListener will always be one step behind, but that is exactly what makes it work.
When submission happens, then url will change to submission id. Then when someone clicks submit button, url changes to the generic problem url, and this is when the listener first reads the old url, and then proceeds with submission.

Perhaps we can add a second delay when someone does manual submit so that UrlChangeListener can read and save url.

@raphaelheinz
Copy link
Owner Author

OK I understand. Thanks for your clarification! I have checked your last commit again :)

I am not yet sure how we could implement a check for the manual push button. We either have the problem that the submission id in the url is lost (when button is clicked) or listener is called too late. Periodically polling is also not be the preferred way I think....
But, do we need an additional check for manual push button? Currently I cannot reproduce my issues anymore - currently it looks good. I will test for possible issues in the next days.

@raphaelheinz
Copy link
Owner Author

I tested in the last days and found an issue with the new approach. If we submit a solution to Leetcode after we have already submitted successfully, the checkmark will turn green immediately and push the previous solution (not the current) to GitHub because the listener is not called yet. Therefore, the solutions on GitHub will be exactly one step behind. Do you know what I mean?

@itsluminous
Copy link
Contributor

Weird, In my case it submits latest code when I click submit button.
My usual process is like this:

  1. Write code in C#
  2. Submit code
  3. Press manual git push button
  4. Write code in Java
  5. Submit code
  6. Press manual git push button

In my case, I always see two different files being pushed.
Also, I have tried submitting different code in same language also, and it would work fine.

@raphaelheinz can you tell step by step how you could replicate issue?

@raphaelheinz
Copy link
Owner Author

raphaelheinz commented Mar 30, 2024

@itsluminous In my daily routine I update and optimize my solutions several times after I have already submitted successfully. Can you check following steps:

  1. Write code in Python
  2. Submit code
  3. Update previous code in Python
  4. Submit code

In the above case step 4) does not upload code 3) but code 1) a second time.
At step 4) the listener is called instantly because the successful submit from step 2) is recognized.

In the previous approach the URL was parsed at that time - now the issue is that the url changed listener has not been called yet 🤔

@itsluminous
Copy link
Contributor

@raphaelheinz I tried the steps you mentioned multiple times. I tried doing same in python as well, still I am not able to replicate.
I am wondering if Edge and Chrome have different behaviour.
I am using Edge.

@raphaelheinz
Copy link
Owner Author

@itsluminous Thanks for your feedback! Hmm, I will check on Edge and Chrome later. Btw I am using Brave on Mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants