Skip to content

Unable to overwrite defaultWebPreferences #688

@JulianGlueck

Description

@JulianGlueck

What were you trying to do?

I am trying to overwrite certain Electron webPreferences for a new window.
In my case, I want to disable the nodeIntegration flag. By default, NativePHP will enable this flag. This is considered unsafe when navigating to external sites (see this page).

Fortunately, NativePHP allows to pass custom web preferences. The problem is though, that it defines defaultWebPreferences and spreads it with the custom ones. Yet, the default ones are spread after the custom ones which means that you cannot overwrite the defaults. See line 301 in the window.ts file.

In my opinion, the current implementation is not correct. Lines 302 and 303 in windows.ts should be switched. But I am unsure, if there was any consideration behind that placement.

I will be happy to create a PR for this issue but wanted to check back with you guys first. 🙂

What happened?

Custom webPreferences will be ignored if already defined in the defaultWebPreferences.

How to reproduce the bug

Simply open a new window and pass any webPreferences that are defined in the defaultWebPreferences like so:

Window::open()
    ->webPreferences([
        'nodeIntegration' => false
    ])
    ->url(...)

These will not be considered.

Debug Output

n/a

Which operating systems have you seen this occur on?

No response

Notes

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions