Ticket #253 (closed task: fixed)

Opened 18 months ago

Last modified 15 months ago

Support dotted-object creation

Reported by: t-bone Owned by: t-bone
Priority: minor Component: Karma Blocker
Version: Severity: Feature
Keywords: Cc:

Description

It's becoming increasingly common for pages to use a new style of Google Analytics ( http://www.google.com/analytics/ one example of this style) that does something like this:

var pageTracker = _gat._getTracker("...");

After including a script that defines _gat. If this script is blocked, the above line generates a JS error. Karma blocker's "function inject" feature is designed to mask these errors, but does not support defining a function in an otherwise nonexistent object. This rule:

[Inject]
function='_get._getTracker'

Should inject (if it does not exist) an empty _gat object, then define a _getTracker property, as a null function.

Attachments

Change History

Changed 16 months ago by t-bone

(In [509]) Refs #253

  • Allow "dotted objects" (i.e. _gat._getTracker) to be injected, not just simple single names.

Changed 16 months ago by t-bone

Only now that I can inject _gat._getTracker, do I realize that it returns an object, and the script continues to call (i.e.) pageTracker._setCookiePath("/analytics/");, and of course _setCookiePath is not a property of the undefined return of my injected function. Not sure if there's any decent way to solve this in general.

Changed 15 months ago by t-bone

  • status changed from new to accepted

With the help of the StackOverflow community, I found __noSuchMethod__, which allows me to solve this perfectly!

Changed 15 months ago by t-bone

  • status changed from accepted to closed
  • resolution set to fixed

(In [523]) Fixes #253

  • Using __noSuchMethod__, create an injected function that will allow all properties of it to be called, and return a function with this property as well. This makes the Google Analytics script not throw errors!

Add/Change #253 (Support dotted-object creation)

Author


E-mail address and user name can be saved in the Preferences.


Action
as closed
The resolution will be deleted. Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.