Tech Note: Bookmarklet Bug Fix

Exterminating an insect
LGF • Views: 16,512

Oops! A bug crept into the new LGF Pages bookmarklet code last night, affecting Firefox and Chrome users; the window would pop open but get stuck at the “Loading” screen.

The problem is now fixed, and it was something very simple — when testing a variable with “typeof,” the keyword “undefined” needs to be in quotes for these browsers.

Anyway, please re-install the “Create A Page” bookmarklet one more time so you’re up to date; everything is now working in all modern browsers. The latest version is 1.1.8.

UPDATE at 11/9/13 12:43:05 pm

How a bug happens:

I had originally written that section of the bookmarklet code as:

if (window.jQuery === undefined)

And that works in all browsers, without the quotes, because you’re comparing against the value undefined. However, this is problematic because it’s possible to declare undefined as a variable and give it a completely different value. Since a bookmarklet needs to be as unobtrusive as possible, I decided to change the code to use the typeof operator, like this:

if (typeof (window.jQuery) === undefined)

But I forgot that typeof returns a string, so you need to compare against ‘undefined’, in quotes, like this:

if (typeof (window.jQuery) === "undefined")

Except in Safari, which will happily do the correct comparison either way, with or without the quotes. I added that new code at the last minute and because it worked in Safari I made the mistake of releasing it into the wild. Safari tricked me by being too forgiving.

And that’s how bugs happen.

Jump to bottom

24 comments
1 Iwouldprefernotto  Sat, Nov 9, 2013 10:33:16am

Please proceed.

2 Political Atheist  Sat, Nov 9, 2013 10:33:21am

WrenchWench that Page you put up is a heck of a wake up call. Well done.

3 Charles Johnson  Sat, Nov 9, 2013 10:37:08am

Safari has no problem with this code:

if (typeof (window.jQuery) === undefined)

But all other browsers need to see this:

if (typeof (window.jQuery) === ‘undefined’)

Web programming. Gotta love it.

4 Dark_Falcon  Sat, Nov 9, 2013 10:45:20am

Pam Geller and the EDL are going to be screaming about this one:

Royal Marine is convicted of murder of Taliban insurgent who was shot in the chest at close range - but two comrades are CLEARED

A Royal Marine has been convicted of murder following the execution of a seriously injured Afghan insurgent in September 2011.

A court martial board found the commando, known only as Marine A, guilty of murdering the man in Helmand Province more than two years ago.

Two others, known as Marines B and C, were acquitted. Marine A will be sentenced on December 6.

SNIP

Marine A shot the Afghan national in the chest at close range with a 9mm pistol before quoting a phrase from Shakespeare as the man convulsed and died in front of him.

‘There you are. Shuffle off this mortal coil, you c***. It’s nothing you wouldn’t do to us,’ Marine A told the insurgent.

He then turned to comrades and said: ‘Obviously this doesn’t go anywhere, fellas. I just broke the Geneva Convention.’

The execution was filmed by a camera mounted on the helmet of Marine B.

Marines B and C were alleged to have been ‘party to the killing’ and ‘encouraged and assisted’ Marine A in committing the murder but they were cleared.

The unusual thing was not that this summary execution happened, but that it was filmed and the shooter punished. The killing of badly wounded enemy combatants is uncommon, but it is something that happens a good number of times in any war. Most of those times it either never comes to light or does so long after the fact.

5 Charles Johnson  Sat, Nov 9, 2013 10:47:24am

How a bug happens:

I had originally written that code as:

if (window.jQuery === undefined)

And that works in all browsers, without the quotes, because you’re comparing against the value undefined. However, this is problematic because it’s possible to declare undefined as a variable and give it a completely different value. Since a bookmarklet needs to be as unobtrusive as possible, I decided to change the code to use the typeof operator.

But I forgot that typeof returns a string, so you need to compare against ‘undefined’, in quotes. EXCEPT in Safari, which will happily do the correct comparison either way.

I added that new code at the last minute and because it worked in Safari I went ahead and released it into the wild. Safari tricked me again by being too forgiving.

6 PhillyPretzel  Sat, Nov 9, 2013 10:57:23am

re: #5 Charles Johnson

Another reason to love my MacBook Pro. :)

7 Backwoods_Sleuth  Sat, Nov 9, 2013 10:58:13am
8 Iwouldprefernotto  Sat, Nov 9, 2013 10:59:12am

re: #7 Backwoods_Sleuth

oh good grief…


White guy wins after leading voters to believe he’s black

True story or Hollywood B movie?

9 William Barnett-Lewis  Sat, Nov 9, 2013 10:59:58am

re: #3 Charles Johnson

Safari has no problem with this code:

if (typeof (window.jQuery) === undefined)

But all other browsers need to see this:

if (typeof (window.jQuery) === ‘undefined’)

Web programming. Gotta love it.

Interesting. All other browsers? I’m wondering if Chrome behaved like Safari in this instance as well since both derive from the same code base?

10 Charles Johnson  Sat, Nov 9, 2013 11:03:57am

re: #9 William Barnett-Lewis

Interesting. All other browsers? I’m wondering if Chrome behaved like Safari in this instance as well since both derive from the same code base?

Nope, Chrome wanted ‘undefined’ to be a string too.

11 Dark_Falcon  Sat, Nov 9, 2013 11:04:32am

re: #8 Iwouldprefernotto

True story or Hollywood B movie?

The reverse of the latter, actually.

12 Charles Johnson  Sat, Nov 9, 2013 11:04:54am

Safari and Chrome are both derived from the Webkit open source code, but they have different Javascript engines.

13 Iwouldprefernotto  Sat, Nov 9, 2013 11:08:58am

re: #11 Dark_Falcon

The reverse of the latter, actually.

So there will be a sequel/remake?

14 Justanotherhuman  Sat, Nov 9, 2013 11:10:49am

re: #8 Iwouldprefernotto

True story or Hollywood B movie?

Maybe he’ll get caught with a live boy in his bed.

If he can lie and deceive so blatantly, surely they’ll catch up with him at some point.

I just hope it’s soon.

15 Skip Intro  Sat, Nov 9, 2013 11:11:45am

Meanwhile, back at the hardware store,

16 Justanotherhuman  Sat, Nov 9, 2013 11:14:26am

Go Wendy!

Sen. Wendy Davis officially files for candidacy to be 48th Governor of Texas

abclocal.go.com

“I’m running for Governor because I believe all Texans should have a voice in their future and a place in Texas’ future,” Davis said. “Today is the official start of that journey — a journey that means so much more than filing paperwork.”

17 Dark_Falcon  Sat, Nov 9, 2013 11:17:55am

re: #16 Justanotherhuman

Go Wendy!

Sen. Wendy Davis officially files for candidacy to be 48th Governor of Texas

abclocal.go.com

“I’m running for Governor because I believe all Texans should have a voice in their future and a place in Texas’ future,” Davis said. “Today is the official start of that journey — a journey that means so much more than filing paperwork.”

Just don’t get your hopes up. The odds are not in her favor. But it’s certainly OK to root for longshots. If it weren’t acceptable I’d be in serious trouble.

18 Eclectic Cyborg  Sat, Nov 9, 2013 11:18:23am

re: #16 Justanotherhuman

Go Wendy!

Sen. Wendy Davis officially files for candidacy to be 48th Governor of Texas

abclocal.go.com

“I’m running for Governor because I believe all Texans should have a voice in their future and a place in Texas’ future,” Davis said. “Today is the official start of that journey — a journey that means so much more than filing paperwork.”

Unfortunately, with Texas gerrymandering, how I’m not sure how much of a chance she has.

19 wrenchwench  Sat, Nov 9, 2013 11:19:12am

re: #15 Skip Intro

Meanwhile, back at the hardware store,

[Embedded content]


If it was an agency, how did they terminate the individual?

20 wrenchwench  Sat, Nov 9, 2013 11:20:25am

re: #17 Dark_Falcon

Just don’t get your hopes up. The odds are not in her favor. But it’s certainly OK to root for longshots. If it weren’t acceptable I’d be in serious trouble.

The way to get people enthused about a political campaign is to get their hopes up.

I’m not in Texas, but my hopes are up for Wendy.

21 William Barnett-Lewis  Sat, Nov 9, 2013 11:21:55am

re: #12 Charles Johnson

Safari and Chrome are both derived from the Webkit open source code, but they have different Javascript engines.

There’s the bit I was unaware of.

22 Dark_Falcon  Sat, Nov 9, 2013 11:34:28am

re: #19 wrenchwench

[Embedded content]


If it was an agency, how did they terminate the individual?

It’s possible the drummers were working for an agency and the picture taker was a Home Depot employee. Operative word: “was”.

23 piratedan  Sat, Nov 9, 2013 11:40:02am

re: #17 Dark_Falcon

I dunno, Texas has elected Democratic governors in the past, and women governors at that. One can look at the quality of the competition and have hope, tempered with the quality of the electorate. One additional item, you can’t gerrymander the entire state and this does include the cites where there is a decidedly blue trend as of late (I believe every major metro area of Texas has a Dem mayor). When it comes time, I’ll most likely toss her some cash, job and finances allowing.

24 GeneJockey  Sat, Nov 9, 2013 11:42:27am

re: #19 wrenchwench

[Embedded content]


If it was an agency, how did they terminate the individual?

“Those responsible for sacking the people who have just been sacked, have been sacked.”


This article has been archived.
Comments are closed.

Jump to top

Create a PageThis is the LGF Pages posting bookmarklet. To use it, drag this button to your browser's bookmark bar, and title it 'LGF Pages' (or whatever you like). Then browse to a site you want to post, select some text on the page to use for a quote, click the bookmarklet, and the Pages posting window will appear with the title, text, and any embedded video or audio files already filled in, ready to go.
Or... you can just click this button to open the Pages posting window right away.
Last updated: 2023-04-04 11:11 am PDT
LGF User's Guide RSS Feeds

Help support Little Green Footballs!

Subscribe now for ad-free access!Register and sign in to a free LGF account before subscribing, and your ad-free access will be automatically enabled.

Donate with
PayPal
Cash.app
Recent PagesClick to refresh
A Closer Look at the Eastman State Bar DecisionTaking a few minutes away from work things to read through the Eastman decision. As I'm sure many of you know, Eastman was my law school con law professor. I knew him pretty well because I was also running in ...
KGxvi
2 hours ago
Views: 71 • Comments: 1 • Rating: 1