Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDVWebViewEngine needs a way to set the websiteDataStore of its configuration #900

Closed
msmtamburro opened this issue Jun 16, 2020 · 1 comment
Milestone

Comments

@msmtamburro
Copy link
Contributor

msmtamburro commented Jun 16, 2020

Feature Request

Motivation Behind Feature

A websiteDataStore can both be configured (e.g., set to non-persistent) and re-used (e.g., in other web browser components).

Feature Description

Optionally exposing the configuration as typically done with the "Cordova settings" model may not suffice. For example, if you only added a Cordova setting for persistent vs. non-persistent, this would still not give us a handle to the websiteDataStore for re-use elsewhere. More specifically, allowing Cordova to use an existing websiteDataStore that was created and used prior to Cordova reaching its createConfigurationFromSettings method is important in my case. You could accomplish this by providing a protocol that allows us to return a websiteDataStore.

For example, add the following lines to CDVWebViewEngine.h:

@protocol CDVWebViewEngineConfigurationDelegate <NSObject>
/// Provides a fully configured WKWebsiteDataStore; useful for customizing configuration
- (nonnull WKWebViewConfiguration *)configuration;
@end

and then expose this property:

@property (nullable, nonatomic, weak) CDVPlugin<CDVWebViewEngineConfigurationDelegate>* configurationDelegate;

And finally, in CDVWebViewEngine.m, inside of createConfigurationFromSettings: start with:

    WKWebViewConfiguration* configuration = [_configurationDelegate configuration];
    if (configuration) {
        return configuration;
    }

Alternatives or Workarounds

When using the CDVWKWebViewEngine (the old plugin), it was possible to override createConfigurationFromSettings to customize portions of the configuration that were not exposed through Cordova settings. With the migration to CDVWebViewEngine, its private status prevents this type of customization without resorting to swizzling.

msmtamburro added a commit to msmtamburro/cordova-ios that referenced this issue Jan 5, 2021
msmtamburro added a commit to msmtamburro/cordova-ios that referenced this issue Jan 5, 2021
* issue_900_websiteDataStore:
  fix: update the existing tests of the default behavior
  feat: add CDVWebViewEngineConfigurationDelegate to fully expose WKWebView configuration (apache#900)

# Conflicts:
#	CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m
@dpogue dpogue added this to the 7.0.0 milestone Oct 1, 2021
dpogue pushed a commit that referenced this issue Oct 1, 2021
* feat: add CDVWebViewEngineConfigurationDelegate to fully expose WKWebView configuration (#900)

* fix: update the existing tests of the default behavior

* chore: bring back initWithFrame, as existing CDVWebViewEngineProtocol conforming plugins use it

* chore: clean up newCordovaViewWithFrame in order to extract initialization with configuration

* chore: find existing methods that can return nil, and mark them as such for clarity
gazben pushed a commit to apicore-engineering/cordova-ios that referenced this issue Aug 26, 2022
* feat: add CDVWebViewEngineConfigurationDelegate to fully expose WKWebView configuration (apache#900)

* fix: update the existing tests of the default behavior

* chore: bring back initWithFrame, as existing CDVWebViewEngineProtocol conforming plugins use it

* chore: clean up newCordovaViewWithFrame in order to extract initialization with configuration

* chore: find existing methods that can return nil, and mark them as such for clarity
@dpogue dpogue modified the milestones: 7.0.0, 7.1.0 Aug 29, 2023
@msmtamburro
Copy link
Contributor Author

Apologies: the code for this fix ended up in the (merged) PR to address 1157. I verified that everything looks good locally in cordova-ios@7.0.1. (I can successfully utilize the CDVWebViewEngineConfigurationDelegate to update the configuration of the CDVWebViewEngine.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants