How to serialize/deserialize Chrome tab (its DOM/RenderTree))? - google-chrome

How to serialize a complete process?
In specially if the process is a Chrome's tab (with its rendered DOM). Is it possible to completely serialize Chrome tab/(tab's DOM) and then to deserialize it again? So that the tab do not need to request HTML via HTTP(S) from the tab's URL again and also do not need to build DOM in the RAM, but instead, just load the DOM and send to render (to OS/GPU?).
Update:
I know, that it looks inefficiently (i.e. each tab process takes about 80 mb of RAM and so much more in a serialized form), but still it is interesting if it is possible to achieve? Hypothetical application: fine-grained serialization of a web-application to the disk and restore it afterwards like it would not (possibly except session tokens) be closed
Update2:
I have just found a thread about the idea behind the question: http://mac-os-forge.2317878.n4.nabble.com/DOM-Serialization-td173772.html . But there is no result in the end of discussion (just somebody found this impractical). The thread is from 2010.
Update3:
there is a question similar to this (just related to iOS app, still about Web View serialization): UIWebView serialization after content has been rendered . Still no solution.
Update4:
Somebody tells about
DOM Level 3 defines Load & Save interface of DOM
http://marc.info/?l=webkit-dev&m=126432160427677
is it something related to save and load the rendered DOM memory model?
Update5:
here [Rendering in Webkit (2009): https://www.youtube.com/watch?v=RVnARGhhs9w] the guy talks about different trees appearing while rendering process (Source Text -> DOM Tree -> RenderObject tree -> RenderStyles -> LineBoxes/Layers). So is it possible to serialize the last structures (RenderStyles -> LineBoxes/Layers) and recreate only them when restoring the tab, not the complete rendering process again? As possible application I find the "Duplicate Tab" command implementation: now it works in the way of rendering from the beginning on the complete page again (from the URL loading). It would be also nice that "Duplicating Tab" would just clone the data structures and re-render only the graphics, not the data structures themselves.
Update6:
this question is very similar: How to save a tab's memory state in Firefox/Chrome?
Update7:
would "process migration" be something reasonable for the solution?

Extracted from http://www.chromium.org/developers/design-documents/oop-iframes/oop-iframes-rendering#TOC-Background
"As each node is added to the DOM tree, the attach() method is called on it which creates an associated renderer "
So you will always need to recreate the DOM in RAM since it is not used as input to a previously existing renderer but also triggers render/s creation.

Related

Inject Schema JSON using Google Tag Manager

We are trying to inject schema JSON for SEO using GTM, however, the page isn't able to detect the schemas while doing the rich result test or schema markup validator.
The schema is getting triggered the - when inspecting the network call. schema json trigger using
Is there something I am missing out on?
Is GTM the right way to trigger schema JSON on a webpage?
Will multiple triggers and GTM tags impact the page speed for the website?
It is possible to inject structured JSON data using GTM. The main downside is, that it is only visible for JavaScript crawlers. In my experience, it is detected and processed by Google, but it works better implementing it backed-side directly into the .
Everything you do impacts page speed. The problem with GTM is, that it appends custom HTML tags to the end of the and moves it up into the afterwards, thus consuming some extra computation power.

"Reverse" JSON Status API

I've been wondering how to fetch the PlayStation server status. They display it on this page:
https://status.playstation.com/en-us/
But PlayStation is known to use APIs instead of PHP database fetches. After looking around in the source code of the site, I found that they have a separate file called /data.json.
https://status.playstation.com/en-us/data.json
The content of this file is the same as the index file (for some reason). They use stuff like {{endDateTitle}} and {{message}}, but I can't find where it's defined, if it's pulled using a separate file or just pulled from a database using PHP.
How can I "reverse" this site and see if there's a API I can use to display the status on my site?
Maybe I did not get the question right, but it seems pretty straightforward.
If using firefox, open Developer tools, Network. Reload the page.
You can clearly see the requested URL
https://status.playstation.com/data/statuses/region/SCEA.json
It seems that an empty list as a status means "No problems" (since there are no problems I cannot verify this assumption. That's all
The parenthesis {{}} are used by various HTML templating languages, like angular, so you'd have to go through the js code to understand where they get updated.

Polymer - Don't load app until geolocation isn't set

I'm currently working on a webapp with the polymer-framework.
However, the whole application depends on the geolocation of the device. I'm setting the location in the app-globals file to use it globally, but it takes some time (around 500ms).
My question now is, how can I say to polymer that it should get to work, after the geolocation is set?
Thanks!
I think it depends on the specific behavior you're looking for. A few cases:
Everything still loads when the page loads, including perhaps some app UI and you have a loading icon or similar to indicate that the app is still starting up while you're waiting for the location.
You don't want to show the app until you have the location. Perhaps you don't want the app resources to be loaded at this time either.
You don't even want Polymer to be loaded until you have the location.
There's a lot of options & they may depend on your app architecture a bit, but for a general structure:
show a loader icon on startup & just wait to populate any templates you have until location is set
perhaps keep the hidden attribute on your main app element until location is available &/or don't append the element to the DOM until this point (although with similar resource loading opportunity caveat as in 3 below).
you could wait to add polymer & related elements until location is available, but generally seems silly to do this since your app could be doing this work while the user is waiting for a location to be found.
If you've got a more specific need then more details are probably needed.

Drupal 7 (VERY) Custom Preview

I have a drupal site that is being used strictly as a CMS that produces JSON feeds using services and services_views, which are consumed by a separate site. What I would like to do (and I have a working proof of concept of this) is allow for a "live preview" on the real site, by intercepting the node form preview / submit, encoding the node as JSON, and loading a special page on the live site that consumes that JSON and displays the page accordingly.
The problem with this JSONized node is, it's different from the JSON being produced by my view (using services_views). My end goal is to produce JSON that is identical for both previewed and non-previewed objects, without having to maintain separate output methods (I could easily hand-customize the json but then when my view for the public api changes I have to make the same changes to the preview json. Trying to avoid this).
I'm looking for feedback on this approach. Is what I'm attempting even possible? The ideas I've been able to come up with so far are:
being able to (conditionally) drive my view with data from a non-databse source
sneakily inserting data into the view object during one of the stages of execution? Kludgy but I'm not above that :)
saving a "clone" node (or revision?) of the node being previewed and let the view use that to display the preview JSON?
Maybe this is the wrong approach altogether and there's something better? (Trying to intercept and format the services output in my module... maybe avoid services_views altogether?)
If anyone can offer some advice, insight or opinions on how to best proceed here, I'd be really grateful.
in a custom module, you could set up a page that grabs the json output from the view page.
$JSON = file_get_contents($url);
that way the preview stays bound to the view, even if the view changes.
First I think it's not an easy task what you are trying to achieve. So before all, good luck.
I think you could intercept the node submission data, then create a node programatically, then render that node, and then export the rendered node to JSON. Inmediately after you get the JSON, delete this node, because the programmatically created node is only for preview.
This task could be more CPU demanding but think that previewing content exactly as the content will look is difficult.
Your rss feeds that your site reads could be filtered with some parameter to avoid programmatically created nodes (prewiew nodes), despite these nodes will be available for a very short time.

What is the complete process from entering a url to the browser's address bar to get the rendered page in browser?

I'm thinking about this question for a long time. It is a big question, since it almost covers all corners related to web developing.
In my understanding, the process should be like:
enter the url to the address bar
a request will be sent to the DNS server based on your network configuration
DNS will route you to the real IP of the domain name
a request(with complete Http header) will be sent to the server(with 3's IP to identify)'s 80 port(suppose we don't specify another port)
server will search the listening ports and forward the request to the app which is listening to 80 port(let's say nginx here) or to another server(then 3's server will be like a load balancer)
nginx will try to match the url to its configuration and serve as an static page directly, or invoke the corresponding script intepreter(e.g PHP/Python) or other app to get the dynamic content(with DB query, or other logics)
a html will be sent back to browser with a complete Http response header
browser will parse the DOM of html using its parser
external resources(JS/CSS/images/flash/videos..) will be requested in sequence(or not?)
for JS, it will be executed by JS engine
for CSS, it will be rendered by CSS engine and HTML's display will be adjusted based on the CSS(also in sequence or not?)
if there's an iframe in the DOM, then a separate same process will be executed from step 1-12
The above is my understanding, but I don't know whether it's correct or not? How much precise? Did I miss something?
If it's correct(or almost correct), I hope:
Make the step's description more precise in your words, or write your steps if there is a big change
Make a deep explanation for each step which you are most familiar with.
One answer per step. Others can make supplement in each answer's comment.
And I hope this thread can help all web developers to have a better understanding about what we do everyday.
And I will update this question based on the answers.
Thanks.
As you say this is a broad question where it's possible to go into great detail on a number of topics. There's nothing wrong with the sequence you described, but you're leaving out a lot of detail. To mention a few:
The DNS layer can help direct clients to different servers based on geographical location to help with load balancing and latency minimization, and one server can respond to requests from many different DNS names.
A browser can make different types of requests (GET, POST, HEAD, etc), and usually includes several different headers including cookies, browser capabilities, language preferences, etc.
Most browsers usually maintain a cache in order to avoid downloading stuff many times, and use various techniques to determine whether the cached version of a file is valid.
In modern webpages there's often complex interaction between many different kinds of files (HTML, CSS, images, JavaScript, video, Flash, ...), and web developers often need detailed knowledge of differences among browsers in order to keep their pages working for everyone
Each of these topics, and many more, could be discussed at length. Perhaps it's more practical to ask more specific questions about the topics you're interested in?
You type maps.google.com(Uniform Resource Locator) into the address bar of your browser and press enter.
Every URL has a unique IP address associated with it. The mapping is stored in Name Servers and this procedure is called Domain Name System.
The browser checks its cache to find the IP Address for the URL.
If it doesn't find it, it checks its OS to find the IP address (gethostname);
It then Checks the router's cache.
It then checks the ISP's cache. If it is not available there the ISP makes a recursive request to different name servers.
It Checks the com name server (we have many name servers such as 'in', 'mil', 'us' etc) and it will redirect to google.com
google.com name server will find the matching IP address for maps.google.com in its’ DNS records and return it to your DNS recursor which will send it back to your browser.
Browser initiates a TCP connection with the server.It uses a three way handshake
Client machine sends a SYN packet to the server over the internet asking if it is open for new connections.
If the server has open ports that can accept and initiate new connections, it’ll respond with an ACKnowledgment of the SYN packet using a SYN/ACK packet.
The client will receive the SYN/ACK packet from the server and will acknowledge it by sending an ACK packet.
Then a TCP connection is established for data transmission!
The browser will send a GET request asking for maps.google.com web page. If you’re entering credentials or submitting a form this could be a POST request.
The server sends the response.
Once the server supplies the resources (HTML, CSS, JS, images, etc.) to the browser it undergoes the below process:
Parsing - HTML, CSS, JS
Rendering - Construct DOM Tree → Render Tree → Layout of Render Tree → Painting the render tree
The rendering engine starts getting the contents of the requested document from the networking layer. This will usually be done in 8kB chunks.
A DOM tree is built out of the broken response.
New requests are made to the server for each new resource that is found in the HTML source (typically images, style sheets, and JavaScript files).
At this stage the browser marks the document as interactive and starts parsing scripts that are in "deferred" mode: those that should be executed after the document is parsed. The document state is set to "complete" and a "load" event is fired.
Each CSS file is parsed into a StyleSheet object, where each object contains CSS rules with selectors and objects corresponding CSS grammar. The tree built is called CSSCOM.
On top of DOM and CSSOM, a rendering tree is created, which is a set of objects to be rendered. Each of the rendering objects contains its corresponding DOM object (or a text block) plus the calculated styles. In other words, the render tree describes the visual representation of a DOM.
After the construction of the render tree it goes through a "layout" process. This means giving each node the exact coordinates where it should appear on the screen.
The next stage is painting–the render tree will be traversed and each node will be painted using the UI backend layer.
Repaint: When changing element styles which don't affect the element's position on a page (such as background-color, border-color, visibility), the browser just repaints the element again with the new styles applied (that means a "repaint" or "restyle" is happening).
Reflow: When the changes affect document contents or structure, or element position, a reflow (or relayout) happens.
i was also searching for the same thing and found this awesome detailed answer being built collaboratively at github
I can describe one point here -
Determining which file/resource to execute, which language interpreter to load.
Pardon me if I am wrong in using interpreter here. There may be other mistakes in my answer, I will try to correct them later and include proper technical terms for things.
When the web server (e.g. apache) has received the URI it checks if there is any existing rewrite rule matching it. In that case the rewritten URI is taken. In either case, if there is no file name to end the URI, the default file is loaded, which is generally index.html or index.php etc. According to the extension of the file name, the appropriate apache module for server-side programming language support is loaded, e.g. mod_php for PHP, mod_python in case of python. The appropriate server side language interpreter (considering interpreted languages like PHP) then prepares the final HTML or output in some other form for the web server which finally sends it as the HTTP response.
I hope above image help you to understand whole process.
Full article is here