-
Notifications
You must be signed in to change notification settings - Fork 16.8k
Add 'webpreferences' attribute to webview #7631
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
Add 'webpreferences' attribute to webview #7631
Conversation
| } | ||
|
|
||
| // parse the 'webpreferences' attribute string, if set | ||
| // this uses the same parsing rules as window.open uses for its features |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to use a common helper method for this so the parsing stays consistent between the two APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I factored out the function into the /lib/common dir, but I can't seem to make the require('../common/parse-features-string') happen in /lib/browser/guest-view-manager.js. I'm guessing this is due to changes to the require search paths. Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any suggestions?
After looking into this a bit more, the code for each wouldn't be the exact same since window.open handles additional features as well which the webpreferences would not, so it might not make sense to have a common function between the two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thought, but I did find a way to make it work, that I think is pretty clean. I just need to solve the require() situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pfrazee want to push it up and I'll take a look at the require issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pfrazee The issue was that new JS files need to be added to filenames.gypi to be included in the built version.
I pushed a couple changes to this pull request, please let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I did find a way to make it work, that I think is pretty clean
Yeah, I really like the way you did it, it makes both use cases easy to follow 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah looks much better.
lib/browser/guest-view-manager.js
Outdated
| if (typeof params.webpreferences === 'string') { | ||
| // split the attribute's value by ',' | ||
| let i, len | ||
| let webpreferencesTokens = params.webpreferences.split(/,\s*/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code from window.open that parses this is left-over from when Electron was using CoffeeScript so it might be nicer to write this new code using ES2015, such as:
params.webpreferences.split(/,\s*/).forEach((pref) => {
let [name, value] = pref.split(/\s*=/)
if (!name) return
value = (value === 'yes' || value === '1') ? true : (value === 'no' || value === '0') ? false : value
if (value === undefined) {
value = true
}
webPreferences[name] = value
})There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can not set webpreferences to a object
|
Thanks @pfrazee for implementing this 👍 🚢 |
|
@pfrazee beaker looks really cool, interested in adding it to http://electron.atom.io/apps/ ? |
@kevinsawicki you bet!
Yeah that'd be great! |
|
Hi, this seemed to be exactly what I would need to change the default font of a webview using webpreferences. However, the setting is defaultFontFamily takes an object as argument (https://github.com/electron/electron/blob/master/docs/api/browser-window.md). How can I encode that as a parameter for the webpreferences attribute? |
Some changes that we're particularly interested in: - electron/electron#8590 - electron/electron#8852 - electron/electron#7631 Note that the `electron-prebuilt` packaged has been renamed to `electron`. Change-Type: patch Changelog-Entry: Upgrade Electron to v1.6.6. Signed-off-by: Juan Cruz Viotti <[email protected]>
Some changes that we're particularly interested in: - electron/electron#8590 - electron/electron#8852 - electron/electron#7631 Note that the `electron-prebuilt` packaged has been renamed to `electron`. Change-Type: patch Changelog-Entry: Upgrade Electron to v1.6.6. Signed-off-by: Juan Cruz Viotti <[email protected]>
|
I also account the same things like ea29738929。Is anyone figure out? |
Per #7431 and #2749, this PR adds a
webpreferencesattribute to the webview tag. The string is implemented using the same parsing logic as the features string inwindow.open.