webkit.opendarwin.org should explain how to detect the latest nightly Some web authors would like to be able to detect that clients are running a more recent version of Safari whereby certain bugs they care about are fixed. It would be great if we could outline a sancioned method for this on webkit.opendarwin.org.
(In reply to comment #0) > webkit.opendarwin.org should explain how to detect the latest nightly > > Some web authors would like to be able to detect that clients are running a more recent version of Safari > whereby certain bugs they care about are fixed. It would be great if we could outline a sancioned method > for this on webkit.opendarwin.org. A system much like Gecko could be useful Gecko uses Gecko/builddate. Where I work at (an online advertisement firm), we use this heavily to work around some bugs. Maybe the versioning of WebKit can include its builddate AppleWebKit/Version.SubVersion.buildDate Sits can assume the lack of such a Date means an official release. Like today for instance: AppleWebKit/Version.SubVersion.build20051229
One issue with changing the user-agent string in this fashion is that it has the potential to break sites that alread parse the user-agent for version information. It is definitely desirable to be able to detect the SVN revision or similar, but it should be done in such a way that it doesn't interact negatively with existing functionality.
Build date seems like a crazy idea to me. We don't want websites to write custom behavior for versions of WebKit that never ship.
There some code for this on the Wiki @ http://trac.webkit.org/projects/webkit/wiki/DetectingWebKit.
Created attachment 12266 [details] js library
Created attachment 12267 [details] sample code
Created attachment 12268 [details] js library I attached the wrong version. Oops.
The code I've attached has a number of advantages over the code currently on trac, including proper namespacing, ability to handle dotted minor revision numbers, independent convenience functions separated by, well, function, and more clear naming and documentation at the API level.
Comment on attachment 12268 [details] js library I don't think that "AppleWebKit" is the right string to search for. I suggest searching for " AppleWebKit/" instead. I suggest breaking the version number string into a list separated by "." rather than using floating point. The version would be an array of integers. A good function would be one that compares two period-separated numbers by searching through each of them a period time. That's how I'd like to compare version numbers.
Comment on attachment 12267 [details] sample code log("You browser " + (isWebKit ? "uses " : "does not use ") + "WebKit.\n"); Typo here "You" instead of "Your". I'd like versionIsAtLeast to take a string parameter instead of two integers.
Created attachment 12283 [details] sample code fixed typo
Created attachment 12284 [details] js library Changed search to AppleWebKit/, changed version to return an array of "." separated numbers.
Also changed versionIsAtLeast to take a string parameter.
Comment on attachment 12284 [details] js library r=me -- a few small thoughts about refinement > return RegExp("AppleWebKit/").test(navigator.userAgent); > var webKitFields = RegExp("(.*AppleWebKit/)([^ ]*)").exec(navigator.userAgent); I think you should require a space before AppleWebKit in both of these regular expressions. Also, I suggest using a + rather than a * in the version number part of the expression. > return undefined; Generally I'd suggest returning null instead of undefined. I think undefined should be reserved for the meaning "this isn't defined at all". > WebKit.versionIsAtLeast = function versionIsAtLeast(minimumString) Why do the functions themselves have names as well as the name of the property of the WebKit object? Is this helpful? > // Defaults to "" > minimumString = String(minimumString); I don't understand the value of this line of code. Are we trying to make this function work if people call with things that aren't strings? Are you sure that WebKit is the best name for this object? I think it works well for the WebKit.versionXXX functions, but not as well for the WebKit.isWebKit.
> > return RegExp("AppleWebKit/").test(navigator.userAgent); > > var webKitFields = RegExp("(.*AppleWebKit/)([^ ]*)").exec(navigator.userAgent); > > I think you should require a space before AppleWebKit in both of these regular > expressions. Also, I suggest using a + rather than a * in the version number > part of the expression. Done. > > return undefined; > > Generally I'd suggest returning null instead of undefined. I think undefined > should be reserved for the meaning "this isn't defined at all". Done. > > WebKit.versionIsAtLeast = function versionIsAtLeast(minimumString) > > Why do the functions themselves have names as well as the name of the property > of the WebKit object? Is this helpful? It's a preferred style in JavaScript because named functions help with debugging. Imagine: var f = WebKit.versionIsAtLeast; ... log("About to call function: " + f); > > // Defaults to "" > > minimumString = String(minimumString); > > I don't understand the value of this line of code. Are we trying to make this > function work if people call with things that aren't strings? I was, but now I think that was a bad idea. > Are you sure that WebKit is the best name for this object? Changed to WebKitDetect. Really, it's intended to be a namespace, not an object.
Marking "fixed" to clear from the review queue. I still need to get privileges before I can upload this to trac.