luciopaiva / witchcraft

Inject Javascript and CSS right from your file system. Think GreaseMonkey for more advanced users.
https://luciopaiva.com/witchcraft
MIT License
254 stars 18 forks source link

Google analytics is causing couples of issues #30

Closed shihshen closed 3 years ago

shihshen commented 3 years ago

Google analytics is causing following issue.

  1. Popup may not work correctly. Sometimes, the server address just shows "host" instead the url and port.
  2. The js and css related to top frame may not be reloaded so the modification of js and css may not be picked up.

I have verified these 2 issues can be fixed by removing google analytics. Can you also let me know why google analytics is needed? As I can see it is sending the URLs users have visited which is part of user behavior. I don't see the necessary to collect user data, and users are not informed when they install this extension.

Thank you, Shih

luciopaiva commented 3 years ago

Hi @powpowshen,

Can you please provide steps on how to reproduce it? Screenshots can also be helpful.

I have verified these 2 issues can be fixed by removing google analytics.

Can you please explain how this was verified? It will help me understand the problem.

As for why Witchcraft uses GA: it is used to help understand and improve user behavior.

As I can see it is sending the URLs users have visited

This is not true. Witchcraft only reports UI interaction (e.g.: user clicked button on Witchcraft popup window) and to send statistics (e.g.: how many times the JS include directive was triggered). Witchcraft does not report any data with respect to the URLs being accessed or the script files being loaded.

If you still feel uncomfortable with it, you are welcome to download the sources, change it to remove GA calls and load it as unpacked extension. But it'd be really useful if you could share the exact situation you had so it can be properly fixed.

Thanks!

luciopaiva commented 3 years ago

Your question about GA is perfectly valid, though. I'll add it to the FAQ.

shihshen commented 3 years ago

Hi Luciopaiva,

Thank you for getting back to me. I missed the message so I just saw your response now.

Thank you for add GA into FAQ. I am not quite sure if GA is the root cause now. However, I am explain these two issues more since I can still see these 2 issues happening without GA.

The first issue that popup may not work correctly. The popup looks like below when it happens.

Screen Shot 2021-02-20 at 6 55 15 PM

It happens quite randomly and frequently. I don't know the exact steps to reproduce it yet. I can also see the reason is background is undefined when it happened.

Screen Shot 2021-02-20 at 7 00 17 PM

The second issue that js and css may not be reloaded. I haven't dive into the code enough to come up with a solution, but I may do it since I can reproduce it easily. What I found so far is that js and css for subdomain may not be reloaded. For example, I have js files like github.com.js and am visiting https://www.github.com. Only www.github.com.js can be reloaded everytime. Sometimes, github.com.js can be reloaded as well. I'll provide more details when I have a chance.

shihshen commented 3 years ago

A little bit update here.

I noticed background page may not be retrieved 30 seconds after latest page reloaded. It seems like the reason is background becomes inactive after all js/css are loaded.

Still trying to figure out why js/css for subdomains may not be loaded. The way I know the js/css for subdomains may not be loaded is that I print out all http accesses and notice the extension doesn't even try to access js/css for subdomains. I can't reproduce this issue after I added logs and try to capture the root cause. So weird! Will keep monitoring it and update here once I find something.

luciopaiva commented 3 years ago

Thank you for getting back to me. I missed the message so I just saw your response now.

No problem, happens to me all the time. The GitHub notification system has a lot to improve.

Thank you for add GA into FAQ.

To be honest, I hadn't done it yet. I just did it now, though.

I can still see these 2 issues happening without GA

Nice! So we can rule out GA.

About issue 1:

I can also see the reason is background is undefined when it happened.

This is very strange. I went to read the docs and the only way it can return something that is not the window is when the extension has no background page:

Returns the JavaScript 'window' object for the background page running inside the current extension. Returns null if the extension has no background page.

Which is obviously not the case. Which OS/Chrome version are you running?

About issue 2:

I have js files like github.com.js and am visiting https://www.github.com. Only www.github.com.js can be reloaded everytime. Sometimes, github.com.js can be reloaded as well. I'll provide more details when I have a chance.

This is very weird too. Witchcraft has a test to guarantee that this works. Please let me know if you get the time to investigate it more.

I noticed background page may not be retrieved 30 seconds after latest page reloaded. It seems like the reason is background becomes inactive after all js/css are loaded.

This is interesting. According to this SO answer, it is possible that a background page may become inactive. Please try setting persistent to true in the manifest.json file and let me know if it works. If it does, the problem is really that the extension is being deactivated by Chrome. It looks like you may have found a real bug!

luciopaiva commented 3 years ago

Both issue 1 and 2 may be related to the extension being deactivated by Chrome. If that's true, setting persistent to true as a workaround should solve both.

I will wait for your test to confirm it works, and then I will take a look at the better solution proposed in that SO answer.

shihshen commented 3 years ago

Setting persistent to true does prevent issue 1 from happening again! Thank you for taking care of this.

However, I don't think issue 2 is something to do with that. I did see the witchcraft test and code. They do look good to me. I am using the latest version of chrome. I'll keep posting updates here once I find something.

luciopaiva commented 3 years ago

Good to hear about issue 1. I will open another issue on GitHub so I can fix it properly soon.

shihshen commented 3 years ago

Thank you!

shihshen commented 3 years ago

Finally figure out issue 2. Had sent out the PR. Please take a look.

luciopaiva commented 3 years ago

Nice investigation, @shihshen! Since the fix is already merged, I am going to close this issue. Thanks!