PacktPublishing / Django-4-by-example

Django 4 by example (4th Edition) published by Packt
https://djangobyexample.com/
MIT License
799 stars 461 forks source link

Chapter 6: Bookmarklet not working in firefox #19

Open codeKing2020 opened 1 year ago

codeKing2020 commented 1 year ago

Hi @zenx , I'm trying to use the bookmarklet bookmark in firefox on amazon to get pictures, but the container does not even load. When I checked the console for issues, it said that the bookmarkLaunch() function is not working. This is maybe because the two js files are not 'connected' well, but I do not know how to solve that. I already tried changing the urls to include 'https://" instead of just '//127...' but that did not work. What should I do?

zenx commented 1 year ago

@codeKing2020 can you paste the console log and attach the .js file?

codeKing2020 commented 1 year ago

dashboard.html bookmarklet.js bookmarklet_launcher.js image

savakarrohan commented 1 year ago

I seem to be having a similar problem, To me it appears that the bookmark_launcher javascript is being truncated. I notice this truncation on every browser(chrome,edge,firefox) Find attached mugshots of respective browser behaviour. I shall comment the same on github too. Solution: Trying on it, I attempted to copy paste the bookmark_launcher unnamed function in to the console and I got a > ERR: BlOCKED BY CLIENT Response. image image Solution Attempt

codeKing2020 commented 1 year ago

Hello @savakarrohan so what I'm getting it that the javascript is being truncated (shortened) by the browser for you? Maybe it could be a proxy/firewall problem? Why not paste your code pertaining to bookmarkking (the HTML, and JS) in a pastebin and send the links.

I attempted to copy paste the bookmark_launcher unnamed function in to the console and I got a > ERR: BlOCKED BY CLIENT Response.

This error is commonly caused due to one of the extensions installed within Chrome. Most likely you will see this error appear if you are using an extension such as Adblock or a browser safety plugin. For example, Adblock or browser safety extensions use a set of parameters which defines what will be blocked.

Did you try disable all extensions? Why not try another site like amazon?

codeKing2020 commented 1 year ago

Personally, I was using Linux when I encountered my problem, and that might've been the issue, because my javascript was nnot being escaped, therefore the code came out wrong and couldn't be parsed. All my gratitude to @zenx who helped me on his discord channel!

savakarrohan commented 1 year ago

@codeKing2020, I just tried the methods you mentioned above.

disable browser extensions

I disabled browser extensions and "reinstalled" the bookmark. "reboomarked" I also tried this on a fresh install of firefox which has no extensions. No change in the output.

Update firewall

I had mcaffee running and disabled the firewall for that. Still have no change in the output.

Try different sites.

I tried all the methods above on amazon.in

Console error when javascript is run

I restarted my server a couple of times, and It appears that running the javascript from bookmarklet_launcher.js works just fine now. so

ERR: BlOCKED BY CLIENT Response. this error is now solved.

So now my only doubt is why is the bookmark cutting off the javascript? notably the number of characters is 120

codeKing2020 commented 1 year ago

I'm sorry but I do not know how to solve this issue, maybe contact the team at discord?

zenx commented 1 year ago

@savakarrohan can you try the following encoded JavaScript for your bookmark?

javascript:(function()%7Bif(window.myBookmarklet!%3D%3Dundefined)%7BmyBookmarklet()%3B%7Delse%7Bdocument.body.appendChild(document.createElement(%27script%27)).src%3D%27https://127.0.0.1:8000/static/js/bookmarklet.js%3Fr%3D%27%2BMath.floor(Math.random()*99999999999999999999)%3B%7D%7D)()%3B
savakarrohan commented 1 year ago

Hi, Sorry for the late response, Yes that piece of code worked. Thank you very much, Could you hint at what you have done:

I suspect you have mentioned to the browser that there is some javascript javascript and everything is in utf8 encoding?

zenx commented 1 year ago

@savakarrohan it looks like there is an issue with URL encoding with the bookmarklet. The previous code is the bookmarklet_launcher.js JS code with URL encoding applied. I wasn't able to replicate this issue. I tested the bookmarklet with/without URL encoding and it worked well in both cases for Chrome and Safari.

pj46280 commented 1 year ago

@zenx The bookmark I created is loading the html template but in that it is not showing any images which are present on the web page, it is totally blank (Screenshot 1). image

Not all sites give the same result in some are showing error in console (Screenshot 2) image

Any help regarding this??