You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 27, 2018. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 27, 2018. It is now read-only.
To build a browser, we need special iframes. To differentiate them, they can be named differently (<browser> or <webview>) or can have a special attribute (mozbrowser=true).
The Mozilla Browser API has been designed and built for Firefox OS. We also use it in Browser.html.
Electron's webview API has been designed for Desktop applications, and is used in many Electron projects.
@Gozala, @benfrancis Can you guys meet and figure out what is the best approach here?
Here are some constraints:
do not break the world: this API needs to work with Firefox OS without too many changes. Ideally, we could build a polyfill on top of the new spec to imitate the old API, or the other way around.
respect specifications: many of the limitations of the Browser API come from the web specification, not from the API design itself.
@kanru and I have discussed trying to standardise a webview HTML tag and associated API with other browser vendors, based on the Mozilla mozbrowser element, Google Webview element and Microsoft webview element. I am happy to be editor of that spec as he suggested, or share that with others.
I think the thing that is currently blocking that standardisation is the lack of a security model fit for the purpose of exposing such an API to web content, given that its purpose is to poke holes in the same-origin policy of the web.
I would recommend against creating a new parallel API to the existing Browser API which isn't working towards a standard, though a poly-fill to meet your needs could be fine.
I think the thing that is currently blocking that standardisation is the lack of a security model fit for the purpose of exposing such an API to web content, given that its purpose is to poke holes in the same-origin policy of the web.
Can we walk around that until we get a proper security model? Can we design an API without the security model in place?
Can we walk around that until we get a proper security model? Can we design an API without the security model in place?
Sure we can design it, but can we get anyone else interested in standardising it unless we know it will actually be usable? A spec written by one browser vendor rarely becomes a standard.
That doesn't stop us from evolving the mozBrowser API to better suit all of our needs, but I think if we want to create a new HTML element we should do that as part of a standardisation process.
@Gozala wants to make some serious changes to the Browser API.
Servo needs a webview/browserAPI implementation.
Should we keep the Browser API and implement/improve it in parallel in both Servo and Gecko?
Should we try to unblock the discussion about the webview API?
I'm not sure all of @Gozala's ideas are consistent with the design direction of the Browser API so far (I commented on bug 1198472), but he should really talk to @kanru who is the module owner, and maybe @sicking.
I don't really know anything about the way existing APIs are being ported to Servo, but I hope we don't end up maintaining two incompatible APIs.
I would recommend we evolve the Browser API internally, to meet the needs of all internal stakeholders, whilst simultaneously trying to unblock the webview standardisation work, because I expect that will take some time.
I would recommend we evolve the Browser API internally, to meet the needs of all internal stakeholders, whilst simultaneously trying to unblock the webview standardisation work, because I expect that will take some time.
Are there any public public discussions about standardizing the Webview API?
At the Servo level, we are not in a hurry. There's already a basic Browser API in place that is good enough to unblock browser.html support. What I don't want us end up doing is spending time implementing the full Browser API in Servo to eventually drop the implementation for the webview API.
If we are talking about a couple of month of work to kick off a draft (does it sound fair?), I'd rather spend time on this rather than implementing the Browser API in Servo.
Yes. I mentioned that in the first comment. Servo supports some events and the goBack/goForward functions. What we're trying to understand here is whether to keep implementing the Browser API or to implement the Webview API instead.
I am not in particular interested in standardizing browser API just yet, mainly due to limitations we run into using our current implementation. I would much rather define some API make use of it in browser.html (maybe in gaia as well) and learn from it. Once we think it's good API then we can try to standardize and get ppl on board. If we standardize what we have no we're stuck with it forever (or at least for a decade).
I would also prefer to define an API without considering all the limitations imposed by current browser engines and only after iterate over that API to make it actually visible at least in engines we care about.
I'm also happy to work on a polyfill that would emulate mozbrowser API using new API to allow smooth transition.
I would be happy to write up the proposal of the API (in a similar format as Electron's webview API is doing a formal spec would take me far too long and likely we would need to iterate over it many times) I would like to have in servo, based on prior art (mozbrowser, electron, ms webview, chrome webview) and our experience of using it. But I don't think all of it could be (or even should be) standardized at least until we thing it's great API for building a browser with it.
If we standardize what we have no we're stuck with it forever (or at least for a decade).
Standardising doesn't mean making what we already have a standard, it means working with other browser vendors to come up with a standard based on the lessons we've all learnt from our own implementations. We already have quite a lot of experience from the last 3+ years using this API in Firefox OS.
I would also prefer to define an API without considering all the limitations imposed by current browser engines and only after iterate over that API to make it actually visible at least in engines we care about.
I'm also happy to work on a polyfill that would emulate mozbrowser API using new API to allow smooth transition.
If you want to create a new API as a research project then that sounds like a great way to further inform the standardisation process, but don't assume that everyone will want to migrate to whatever you create.
Some of the "limitations" of the mozBrowser API you describe are (for better or worse) intentional design decisions (some of them made by people who no longer contribute to the project). I would prefer to explore whether they were good design decisions and then iterate on the existing API than throw it away and create a new one, at least in our production code.
That's really the wrong place to provide feedback on the mozBrowser API, but I think you already realised that as you started filing bugs in Bugzilla too. Those bugs should really be in the DOM component rather the Firefox OS Runtime component though.
I would be happy to write up the proposal of the API (in a similar format as Electron's webview API is doing a formal spec would take me far too long and likely we would need to iterate over it many times) I would like to have in servo.
I would be interested to see that, and I'm sure Kan-ru and others would be too :) I'm excited to see what we can come up with between us, the current API is quite bloated and could do with some love!
We have to be pretty damn sure we won't implement a new API that will make Gaia people unhappy, or that will be incompatible with a future standardized API (if that ever happens). Implementing such an API will take time. We want to be sure that the API will stick.
We have to sync up with other parties (Mozilla (Gaia, DOM and standard people) and other vendors).
If that is too much work, we should just fix the Browser API as it is, and implement this API in Servo.
IMO we should think about what's the target consumer of this API and if it's worth to standardize it. If it's sole purpose is for creating a browser-like application or a web runtime then a more powerful set of APIs for embedding may be better. Think of nsWebBrowser and related interfaces.
For browser API we should try to limit the interface to navigation and events, otherwise it will soon become a kitchen sink as we learned from nsWebShell/nsDocShell. For needs like enable/disable extensions, inject scripts, taking screenshots, should be extensions to the minimal browser API interface.
And yes, I'd like to understand what makes you unhappy about current Browser API.
@kanru will understand this better than me, but I thought the reason for them being async was to not block the main thread. We call these methods on every navigation of the browser. Why do you want them to be synchronous? Is it just so it's easier to consume?
I'm in favour of the name change (I suggested canGoBack in the first place), but I think if we create new methods they should probably return a Promise.
@paulrouget wanted me to list problems I have with the current mozbrowser API. There is a meta issue with a list of specific issues at servo/servo/#7083 but it may not be easy to follow it so I'm going to list most problems with some insights here, unfortunately in some cases I don't have a though out a proposal on how to fix them.
Disclamer: We do use react.js that reveals some of the API issues that I'm going to point out. On the first thought it may seem like issues or limitations of react, but in reality the issue is that mozbrowser API diverges from declarative nature of HTML that react presumes. Either way I think high level abstraction like react get more and more popular which IMO is natural evolution there for it would be a mistake to introduce any new APIs that are incompatible with a direction of the modern web.
Even bubbling / capturing is a mess. There is no deterministic behavior in some cases embedder can handle / prevent events before it reaches content of the mozbrowser and in other cases it can not. It's specially messy for keyboard events some OS level keybindings seem to trigger on the content while others do not we still have a specific outstanding issue Cmd-Arrow native keybindings and navigation shortcuts conflict #317 related to this. I think the most reasonable to implement same bubbling / capturing as with regular iframes so that outer document could cancel propagation with a capture phase and content document could cancel bubbling to outer document by canceling event in bubbling phase. I won't even start talking about scroll events.
Edit control manipulation in the content document is not possible as far as I can tell. We just hope that OS level controls will work as expected although as pointed out in Cmd-Arrow native keybindings and navigation shortcuts conflict #317 it's not always possible given the issue pointed out above. But if we would like to let user redefine keybindings than all bets are off. That has not being a serious issue for us yet although I still think that is something that embedder needs to have a control of.
API should not have attributes that completely change the behavior. Attributes like mozbrowser and remote completely change behavior of the iframe, well actually they don't changing values of those attributes after element is in the document has no effect. That makes it really difficult to use this API with libraries like react that instead take care of DOM updates for you. It's also is pretty unusual behavior in comparison to rest of the DOM APIs. I would suggest to use different elements for a different types of webviews / iframes so that user can not run into a pitfall of changing attribute having no effect. It may seem that just fixing attributes so that they change behavior of an element is an alternative solution, while that would indeed solve some issue it will still leave some pitfalls. As far as I can tell you can not possibly change non remote iframe to remote without consequences like reloading a document loosing a browsing history etc.. So why just make different elements than it's crystal clear you can't just change behavior if you need remote iframe you need to create new different element.
navigation API for iframe is awkward requires you bookkeeping and given just a DOM element script is unable to detect what the current state is. Let's start with an obvious one - location. Given an iframe element I can't tell what the location of the document loaded. Maybe iframe.src although user may have clicked a link or page may have used history.pushState / replaceState. Sure one could listen to location change events to have an idea what the location but that just isn't great. What makes it even worse that we can't also update src to reflect current location as that would reload page, instead we need to track locationchangeevents to recreate a state of the iframe location and if user modifies a location we would ideally check that location it tries to change it to is not the one that iframe is currently on to avoid reload by jus changing src. Location is not the odd bullet there is also canGoBack and canGoForward where we can't event listen to events to keep track of that state instead we need to use promise API to get recreate state. I'd much rather get those values with locationchange event and just had a plain getters / attributes webview / mozbrowser element (internally they can be updated once event listeners are dispatched). In fact I'm pretty unhappy with browser history in general that it's linear and there is no way of accessing / controlling it's length, entries is just very limiting. I will propose a solution in a separate comment as it will resolve few other issues that will follow in the list.
This is similar to above. Methods goBack / goForward / reload / stop aren't great for several reasons. 1. They don't mix all that well with react or other DOM abstraction libraries as they are not declarative and require imperative calls. 2. Same as above state of webview / mozbrowser is no longer clear from element unless again we keep track of our calls to those methods and store that somewhere but even then we don't always have an event telling that that action has completed, not to mention that embedded document could also trigger history.goBack() and then we have idea again. I think the best compromise without changing API too much would be to add something like document.readyState that could have values like uninitialized / going back / going forward / reloading / stoping / loading / interactive / complete. If that was also exposed as an attribute that would even make API declarative and there for make it compatible with DOM abstraction libraries.
Screenshot API is too slow and it waits for load to end and only succeeds in certain conditions when it does not request stay pending forever.
mozbrowser events don't carry enough information to asses if they are still relevant for this session. More specifically if you change location tree times in a row you get three sets of navigation events after third location change.
Sometimes location change event is triggered several times per load.
API to interact with loaded content. @paulrouget implemented a solution in form of iframe.executeScript that address simple case like "what the current state of this" use cases but is unable to handle cases like "react to this change" in the content document. In fact later is a superset of former so I really think we need an API for later. What I think would make most sense is to have kind of outer shells for remote iframes that for the embedder will seem like a diff domain iframe meaning it could exchange messages with it. Those outer frames will have an access to the actual content document as that document was loaded in the iframe of the same document with a same origin with a difference that inner document will see itself as top one. In a way it's pretty much what we do with frameScripts but instead of defining whole new set of APIs we just relay on existing ones. Loading a script into outer frame could be done via script attribute on an embedded webview / iframe. This would allow script to set up all the listeners it needs and communicate with an embedder or a content document via postMessage or via MessageChannel.
mozbrowser's mozbrowseropen(window|tab) events are the worst. Ok this is API is not just awkward and incompatible with DOM abstraction libraries like react but it's also a minefield. To start with it's really difficult to integrate with libraries that handle DOM for you, because they do take responsibly of DOM but then you get event.detail.iframeElement and you have to make that library to adopt it. But even if that was not difficult enough you need to make it inject it into a document in the event handler cause that iframe is a cinderella loosing all the magic on the next tick that basically prevents us from having async rendering loop. There is some back and forth on the possible alternatives in Fix pinch sensitivity #533 but again this issue has being by far the worst I had to deal with.
I think fundamental problem that is root of most issues above is that API we are given is this box where you can display a single page and there are some knobs to load a different page and jump between pages but what we actually seek is API to per page that we can box on our own. This is vague so let me try to explain with an example of how I think it should look like. I think it would make a lot more sense to have an API designed around navigation entries something more like a
Idea here is that navigation history entries are represented via webpage DOM elements and they have their own location bound to them. If node is removed from document it's removed from the navigation history (if inserted back into the DOM tree content will load again no guarantees about loading from cache though). If the there is no src nothing is loaded. for attribute is used to group web pages into same a same webview group so that same session store, process etc could be used. selected attribute is semantically equivalent to <select><option selected/></select> in terms of behavior there are several options that I list in order of preference:
If selected attribute is set webpage is fully interactive. If attribute is not set then entry goes into a hfcache. Multiple webpage elements for the same webview can be selected. Presumably this option is impossible in gecko but maybe there is a hope for it in servo ?
Just like above with a difference that only one webpage for the same webview group can be selected. If attempt to set it to two webpage elements is made last one causes rest to loos selected attribute. If webpage that has no selected set is inactive and is displayed like an image that is a screenshot of the webpage as it was last when selected was set. Presumably this is implementable both in gecko and servo as this is just a sugar on top of existing navigation API with only difference being that navigation history graph can be non linear.
Just like second option with a difference that webpage tags need to be children of webview instead of using a for attribute. This is less preferable as it implies certain constraints on layout.
It would be ideal if webpage tag was not a scrollable container for an embedded page like iframe is but was rather had a width and height of embedded content. We could then deal with scrolling just by putting it insight container with overflow: scroll. That would also fixed bunch of scroll synchronization issues and I believe that would made #355 non issue as well, but I might be wrong.
With such an API we would not get mozbrowserlocationchanged event but rathe a request to navigate to certain uri. Embedder than would create new webpage entry for that uri and mark it selected. Most of the state and navigation issues would also go away because it will be up to embedder to deal with that goBack will be mark previous sibling node selected, goForward mark next sibling node selected, reload would be remove webpage and create new one with a matching src and for. Not sure about stop to be honest. As of "current location" it's also an src of the webpage that has selected attribute.
Thank you @Gozala. This is great. I agree with most of the points you're listing in #639 (comment)
I won't even start talking about scroll events.
What's wrong with scroll events?
Edit control manipulation in the content document is not possible as far as I can tell
Electron has a nice API for that.
I disagree with the history management system you're suggesting though:
mozbrowser / webview should not just navigate away telling us mozbrowserlocationchanged rather it should request to navigate away. There is some discussion on this subject in #553
mozbrowser's mozbrowseropen(window|tab) events are the worst. Ok this is API is not just awkward and incompatible with DOM abstraction libraries like react but it's also a minefield. To start with it's really difficult to integrate with libraries that handle DOM for you, because they do take responsibly of DOM but then you get event.detail.iframeElement and you have to make that library to adopt it. But even if that was not difficult enough you need to make it inject it into a document in the event handler cause that iframe is a cinderella loosing all the magic on the next tick that basically prevents us from having async rendering loop. There is some back and forth on the possible alternatives in #533 but again this issue has being by far the worst I had to deal with.
Because we use iframes, and as long as we use iframes, I'm afraid there's no better solution.
As for your proposal in #639 (comment) , it requires exposing a lot of the internal mechanisms, and it interacts a lot with how navigation works, which is dictated by the HTML specification. So this would need to be very carefully design to not violate the navigation, caching and browsing context specifications, and to not impact the performance. I don't know about the implementation complexity.
So, 2 things:
We can solve most of the problem you mention in the current Browser API implementation. Both in Gecko an Servo. It is easy and can be done as a short term plan. I can work on a proposal (addressing the issues you mention, while still being compatible with the current Browser API, we don't want to mess up Gaia). Once I get this proposal, I'll ask someone to review it (work will happen in bugzilla), file (and maybe fix) the relevant bugs for Gecko, and make sure Servo implement this updated Browser API (thinking of adding a Browser API test suite to Servo).
Going away from iframes and letting the main process manage navigation (your webview/webpage proposal) would require first a proper document explaining exactly how that would work in accordance to the specification. This is hard, and coming up with the right API will take time, and the implementation, if it ever happens, will also take time. I suggest that we see how we feel with the improved Browser API, and then reevaluate this plan.
My understanding is there are no immediate plans to implementing new browser API, until that changes designing such a new API is just a waste of time so, I'm closing this.
We can start new thread when this work will be more relevant.
Activity
benfrancis commentedon Aug 26, 2015
@kanru and I have discussed trying to standardise a webview HTML tag and associated API with other browser vendors, based on the Mozilla mozbrowser element, Google Webview element and Microsoft webview element. I am happy to be editor of that spec as he suggested, or share that with others.
As you noticed, I made a start on that http://benfrancis.github.io/webview/ and Kan-Ru has done a comparison of those existing APIs https://wiki.mozilla.org/WebAPI/BrowserAPI/Common_Subset
I think the thing that is currently blocking that standardisation is the lack of a security model fit for the purpose of exposing such an API to web content, given that its purpose is to poke holes in the same-origin policy of the web.
There is perhaps some hope for this in the new Firefox OS security model https://wiki.mozilla.org/FirefoxOS/New_security_model which uses a cryptographically signed version of the W3C TAG's proposed streamable package format http://w3ctag.github.io/packaging-on-the-web/ and Google have expressed a vague interest in this too.
I would recommend against creating a new parallel API to the existing Browser API which isn't working towards a standard, though a poly-fill to meet your needs could be fine.
paulrouget commentedon Aug 26, 2015
Can we walk around that until we get a proper security model? Can we design an API without the security model in place?
benfrancis commentedon Aug 26, 2015
Sure we can design it, but can we get anyone else interested in standardising it unless we know it will actually be usable? A spec written by one browser vendor rarely becomes a standard.
That doesn't stop us from evolving the mozBrowser API to better suit all of our needs, but I think if we want to create a new HTML element we should do that as part of a standardisation process.
paulrouget commentedon Aug 26, 2015
@Gozala wants to make some serious changes to the Browser API.
Servo needs a webview/browserAPI implementation.
Should we keep the Browser API and implement/improve it in parallel in both Servo and Gecko?
Should we try to unblock the discussion about the webview API?
What do you recommend?
benfrancis commentedon Aug 26, 2015
I'm not sure all of @Gozala's ideas are consistent with the design direction of the Browser API so far (I commented on bug 1198472), but he should really talk to @kanru who is the module owner, and maybe @sicking.
I don't really know anything about the way existing APIs are being ported to Servo, but I hope we don't end up maintaining two incompatible APIs.
I would recommend we evolve the Browser API internally, to meet the needs of all internal stakeholders, whilst simultaneously trying to unblock the webview standardisation work, because I expect that will take some time.
paulrouget commentedon Aug 26, 2015
Are there any public public discussions about standardizing the Webview API?
At the Servo level, we are not in a hurry. There's already a basic Browser API in place that is good enough to unblock browser.html support. What I don't want us end up doing is spending time implementing the full Browser API in Servo to eventually drop the implementation for the webview API.
If we are talking about a couple of month of work to kick off a draft (does it sound fair?), I'd rather spend time on this rather than implementing the Browser API in Servo.
@kanru @sicking, what are your opinions on this?
metajack commentedon Aug 26, 2015
@paulrouget Servo has some mozbrowser support. See https://github.com/glennw/servo-shell for an example client and you must use
-eflag on Servo to enable it.paulrouget commentedon Aug 26, 2015
Yes. I mentioned that in the first comment. Servo supports some events and the
goBack/goForwardfunctions. What we're trying to understand here is whether to keep implementing the Browser API or to implement the Webview API instead.metajack commentedon Aug 26, 2015
Sorry. Reading is hard.
Gozala commentedon Aug 26, 2015
I am not in particular interested in standardizing browser API just yet, mainly due to limitations we run into using our current implementation. I would much rather define some API make use of it in browser.html (maybe in gaia as well) and learn from it. Once we think it's good API then we can try to standardize and get ppl on board. If we standardize what we have no we're stuck with it forever (or at least for a decade).
I would also prefer to define an API without considering all the limitations imposed by current browser engines and only after iterate over that API to make it actually visible at least in engines we care about.
I'm also happy to work on a polyfill that would emulate mozbrowser API using new API to allow smooth transition.
I have tried to provide relevant feedback to http://benfrancis.github.io/webview/ list some of the constraints we run into using mozbrowser. In browser.html in some cases we actually polyfill API we would like to have, but there several major issues that can't really be polifilled.
I would be happy to write up the proposal of the API (in a similar format as Electron's webview API is doing a formal spec would take me far too long and likely we would need to iterate over it many times) I would like to have in servo, based on prior art (mozbrowser, electron, ms webview, chrome webview) and our experience of using it. But I don't think all of it could be (or even should be) standardized at least until we thing it's great API for building a browser with it.
benfrancis commentedon Aug 26, 2015
Standardising doesn't mean making what we already have a standard, it means working with other browser vendors to come up with a standard based on the lessons we've all learnt from our own implementations. We already have quite a lot of experience from the last 3+ years using this API in Firefox OS.
If you want to create a new API as a research project then that sounds like a great way to further inform the standardisation process, but don't assume that everyone will want to migrate to whatever you create.
Some of the "limitations" of the mozBrowser API you describe are (for better or worse) intentional design decisions (some of them made by people who no longer contribute to the project). I would prefer to explore whether they were good design decisions and then iterate on the existing API than throw it away and create a new one, at least in our production code.
That's really the wrong place to provide feedback on the mozBrowser API, but I think you already realised that as you started filing bugs in Bugzilla too. Those bugs should really be in the DOM component rather the Firefox OS Runtime component though.
I would be interested to see that, and I'm sure Kan-ru and others would be too :) I'm excited to see what we can come up with between us, the current API is quite bloated and could do with some love!
paulrouget commentedon Aug 27, 2015
Introducing a new API is hard.
We have to be pretty damn sure we won't implement a new API that will make Gaia people unhappy, or that will be incompatible with a future standardized API (if that ever happens). Implementing such an API will take time. We want to be sure that the API will stick.
We have to sync up with other parties (Mozilla (Gaia, DOM and standard people) and other vendors).
If that is too much work, we should just fix the Browser API as it is, and implement this API in Servo.
paulrouget commentedon Aug 27, 2015
Can we have a summary of the things we (gaia & browser.html people) don't like about the Browser API?
I'd like to understand if it's enough to just fix the current Browser API or if a brand new API is required.
Also - maybe this discussion should happen in dev-b2g / dev-gaia.
kanru commentedon Aug 27, 2015
IMO we should think about what's the target consumer of this API and if it's worth to standardize it. If it's sole purpose is for creating a browser-like application or a web runtime then a more powerful set of APIs for embedding may be better. Think of nsWebBrowser and related interfaces.
For browser API we should try to limit the interface to navigation and events, otherwise it will soon become a kitchen sink as we learned from nsWebShell/nsDocShell. For needs like enable/disable extensions, inject scripts, taking screenshots, should be extensions to the minimal browser API interface.
And yes, I'd like to understand what makes you unhappy about current Browser API.
2 remaining items
benfrancis commentedon Sep 1, 2015
@kanru will understand this better than me, but I thought the reason for them being async was to not block the main thread. We call these methods on every navigation of the browser. Why do you want them to be synchronous? Is it just so it's easier to consume?
I'm in favour of the name change (I suggested canGoBack in the first place), but I think if we create new methods they should probably return a Promise.
This should really be discussed in Bugzilla.
paulrouget commentedon Sep 1, 2015
We will.
Gozala commentedon Sep 8, 2015
@paulrouget wanted me to list problems I have with the current mozbrowser API. There is a meta issue with a list of specific issues at servo/servo/#7083 but it may not be easy to follow it so I'm going to list most problems with some insights here, unfortunately in some cases I don't have a though out a proposal on how to fix them.
Disclamer: We do use react.js that reveals some of the API issues that I'm going to point out. On the first thought it may seem like issues or limitations of react, but in reality the issue is that mozbrowser API diverges from declarative nature of HTML that react presumes. Either way I think high level abstraction like react get more and more popular which IMO is natural evolution there for it would be a mistake to introduce any new APIs that are incompatible with a direction of the modern web.
mozbrowserandremotecompletely change behavior of theiframe, well actually they don't changing values of those attributes after element is in the document has no effect. That makes it really difficult to use this API with libraries like react that instead take care of DOM updates for you. It's also is pretty unusual behavior in comparison to rest of the DOM APIs. I would suggest to use different elements for a different types of webviews / iframes so that user can not run into a pitfall of changing attribute having no effect. It may seem that just fixing attributes so that they change behavior of an element is an alternative solution, while that would indeed solve some issue it will still leave some pitfalls. As far as I can tell you can not possibly change non remote iframe to remote without consequences like reloading a document loosing a browsing history etc.. So why just make different elements than it's crystal clear you can't just change behavior if you need remote iframe you need to create new different element.iframeelement I can't tell what the location of the document loaded. Maybeiframe.srcalthough user may have clicked a link or page may have usedhistory.pushState / replaceState. Sure one could listen to location change events to have an idea what the location but that just isn't great. What makes it even worse that we can't also updatesrcto reflect current location as that would reload page, instead we need to tracklocationchangeeventsto recreate a state of the iframe location and if user modifies a location we would ideally check that location it tries to change it to is not the one that iframe is currently on to avoid reload by jus changing src. Location is not the odd bullet there is alsocanGoBackandcanGoForwardwhere we can't event listen to events to keep track of that state instead we need to use promise API to get recreate state. I'd much rather get those values withlocationchangeevent and just had a plain getters / attributes webview / mozbrowser element (internally they can be updated once event listeners are dispatched). In fact I'm pretty unhappy with browser history in general that it's linear and there is no way of accessing / controlling it's length, entries is just very limiting. I will propose a solution in a separate comment as it will resolve few other issues that will follow in the list.goBack/goForward/reload/stoparen't great for several reasons. 1. They don't mix all that well with react or other DOM abstraction libraries as they are not declarative and require imperative calls. 2. Same as above state of webview / mozbrowser is no longer clear from element unless again we keep track of our calls to those methods and store that somewhere but even then we don't always have an event telling that that action has completed, not to mention that embedded document could also triggerhistory.goBack()and then we have idea again. I think the best compromise without changing API too much would be to add something likedocument.readyStatethat could have values likeuninitialized/going back/going forward/reloading/stoping/loading/interactive/complete. If that was also exposed as an attribute that would even make API declarative and there for make it compatible with DOM abstraction libraries.iframe.executeScriptthat address simple case like "what the current state of this" use cases but is unable to handle cases like "react to this change" in the content document. In fact later is a superset of former so I really think we need an API for later. What I think would make most sense is to have kind of outer shells for remote iframes that for the embedder will seem like a diff domain iframe meaning it could exchange messages with it. Those outer frames will have an access to the actual content document as that document was loaded in the iframe of the same document with a same origin with a difference that inner document will see itself as top one. In a way it's pretty much what we do with frameScripts but instead of defining whole new set of APIs we just relay on existing ones. Loading a script into outer frame could be done viascriptattribute on an embeddedwebview/iframe. This would allow script to set up all the listeners it needs and communicate with an embedder or a content document viapostMessageor via MessageChannel.mozbrowserlocationchangedrather it should request to navigate away. There is some discussion on this subject in mozbrowser should not navigate away but rather ask us to navigate away #553mozbrowseropen(window|tab)events are the worst. Ok this is API is not just awkward and incompatible with DOM abstraction libraries like react but it's also a minefield. To start with it's really difficult to integrate with libraries that handle DOM for you, because they do take responsibly of DOM but then you getevent.detail.iframeElementand you have to make that library to adopt it. But even if that was not difficult enough you need to make it inject it into a document in the event handler cause that iframe is a cinderella loosing all the magic on the next tick that basically prevents us from having async rendering loop. There is some back and forth on the possible alternatives in Fix pinch sensitivity #533 but again this issue has being by far the worst I had to deal with.Gozala commentedon Sep 8, 2015
I think fundamental problem that is root of most issues above is that API we are given is this box where you can display a single page and there are some knobs to load a different page and jump between pages but what we actually seek is API to per page that we can box on our own. This is vague so let me try to explain with an example of how I think it should look like. I think it would make a lot more sense to have an API designed around navigation entries something more like a
Idea here is that navigation history entries are represented via
webpageDOM elements and they have their own location bound to them. If node is removed from document it's removed from the navigation history (if inserted back into the DOM tree content will load again no guarantees about loading from cache though). If the there is nosrcnothing is loaded.forattribute is used to group web pages into same a same webview group so that same session store, process etc could be used.selectedattribute is semantically equivalent to<select><option selected/></select>in terms of behavior there are several options that I list in order of preference:webpageis fully interactive. If attribute is not set then entry goes into a hfcache. Multiplewebpageelements for the samewebviewcan be selected. Presumably this option is impossible in gecko but maybe there is a hope for it in servo ?webpagefor the samewebviewgroup can be selected. If attempt to set it to twowebpageelements is made last one causes rest to loosselectedattribute. Ifwebpagethat has noselectedset is inactive and is displayed like an image that is a screenshot of thewebpageas it was last whenselectedwas set. Presumably this is implementable both in gecko and servo as this is just a sugar on top of existing navigation API with only difference being that navigation history graph can be non linear.webpagetags need to be children ofwebviewinstead of using aforattribute. This is less preferable as it implies certain constraints on layout.It would be ideal if
webpagetag was not a scrollable container for an embedded page likeiframeis but was rather had a width and height of embedded content. We could then deal with scrolling just by putting it insight container withoverflow: scroll. That would also fixed bunch of scroll synchronization issues and I believe that would made #355 non issue as well, but I might be wrong.With such an API we would not get
mozbrowserlocationchangedevent but rathe a request to navigate to certainuri. Embedder than would create newwebpageentry for thaturiand mark itselected. Most of the state and navigation issues would also go away because it will be up to embedder to deal with thatgoBackwill be mark previous sibling node selected,goForwardmark next sibling node selected,reloadwould be removewebpageand create new one with a matchingsrcandfor. Not sure aboutstopto be honest. As of "current location" it's also ansrcof thewebpagethat hasselectedattribute.paulrouget commentedon Sep 9, 2015
Thank you @Gozala. This is great. I agree with most of the points you're listing in #639 (comment)
What's wrong with scroll events?
Electron has a nice API for that.
I disagree with the history management system you're suggesting though:
I explain in #553 why this is rather difficult.
Because we use iframes, and as long as we use iframes, I'm afraid there's no better solution.
As for your proposal in #639 (comment) , it requires exposing a lot of the internal mechanisms, and it interacts a lot with how navigation works, which is dictated by the HTML specification. So this would need to be very carefully design to not violate the navigation, caching and browsing context specifications, and to not impact the performance. I don't know about the implementation complexity.
So, 2 things:
paulrouget commentedon Sep 11, 2015
I wrote down an exhaustive list of the events currently supported by the Browser API, with a description of all the fields:
https://gist.github.com/paulrouget/37c10519b890757beff2
This + the webidl (http://mxr.mozilla.org/mozilla-central/source/dom/webidl/BrowserElement.webidl), we have a proper description of the Browser API.
I'll consolidate this list, then find a way to move that into m-c, then we'll have a something that more or less look like a spec for the Browser API.
Then we can start looking at what we want to change exactly.
Gozala commentedon Sep 11, 2015
@paulrouget could you please put it in some repo so that I could send pull requests / comments on fields for events I would find helpful ?
paulrouget commentedon Sep 12, 2015
@Gozala I will.
paulrouget commentedon Sep 16, 2015
Here is a repo with a up-to-date description of the current spec: https://github.com/paulrouget/mozBrowserAPI/
Gozala commentedon Jan 12, 2016
My understanding is there are no immediate plans to implementing new browser API, until that changes designing such a new API is just a waste of time so, I'm closing this.
We can start new thread when this work will be more relevant.