Totally makes sense that when IAB is used as a dependency we wouldn't want
window.open() to be changed. Possibly we could add logic to do different
things when a plugin is a dependency vs. required explicitly, but I think
that might overcomplicate things.

I think it makes sense to keep require() for use by plugins, and to expose
a proper API for use by apps.

Preference might make sense, but I don't think there's an easy way to
access the value of the preference from JS, so it's probably more work than
it's worth since it's a one-liner in JS to switch the behaviour:

delete window.open // Reverts the call back to it's prototype's default

window.open = cordova.InAppBrowser.open // Enable IAB by default


Might be a good idea to document the first example in the README until we
no longer clobber by default.

On Fri, Feb 13, 2015 at 8:14 AM, Michal Mocny <[email protected]> wrote:

> Open question: do we even need to clobber a symbol, or would
> cordova.require('org.apache.cordova.iab').open() suffice?
>
> Could we leave compatibility by default, but support opting-in to the
> switch now?  Perhaps a <runs/> flag in the plugin and clobber window.open
> from javascript only if a <preference name="IABShouldNotClobberWindowOpen">
> is not set, instead of using unconditional <clobbers/> from plugin.xml?
> That may have a slight implication about when the clobber happens during
> startup, but is unlikely to be an issue in practice.
>
> -Michal
>
> On Thu, Feb 12, 2015 at 5:19 PM, Jason Chase <[email protected]> wrote:
>
> > For CB-8444, I'm proposing to eventually remove the clobber of
> > 'window.open' that is done by the InAppBrowser plugin.
> >
> > The problem I'm trying to solve is unintended changes to the behaviour of
> > window.open calls in an app.  An example of untended change is an app
> that
> > adds a plugin which provides an external web-based authentication flow.
> > The plugin has a dependency on InAppBrowser, in order to provide the
> > web-based login.  The app developer would likely be unaware that the
> > InAppBrowser plugin clobbers window.open.  As a result, window.open calls
> > that would open the system browser, will show the pages in the
> InAppBrowser
> > instead.
> >
> > The first step is to add a new API to access the InAppBrowser, instead of
> > window.open.  The behaviour of the plugin is unchanged, it's just
> accessed
> > via a different symbol.  This is covered by the referenced pull request
> > [1].
> >
> > In a future major release, the second step is to remove the clobber of
> > window.open.  If an app wishes all window.open calls to be handled by the
> > InAppBrowser, the app can explicitly implement the clobber.  Conversely,
> > other apps are no longer forced to work around the clobber of
> window.open.
> >
> > I'd welcome any comments on this proposal.  This includes any example use
> > cases that want the clobber of window.open by the plugin.
> >
> > Thanks,
> > Jason
> > Google Cordova Team
> >
> > [1] https://github.com/apache/cordova-plugin-inappbrowser/pull/80
> >
>

Reply via email to