Skip to content

馃悰 JavaScript injected before <title>#115

Description

@mountainash

The client.title is always empty as the injected script runs before it's been set in the HTML DOM.

<!DOCTYPE html><html lang="en"><head><script>"use strict";
const webcm = {
    pageVars: { __client: {} },
    _processServerResponse: async (res) => {
        const data = res.json ? await res.json() : res;
        for (const [url, opts] of data.fetch)
            fetch(url, opts);
        for (const [key, val] of data.pageVars)
            webcm.pageVars[key] = val;
        for (const e of data.execute)
            eval(e);
        return data.return;
    },
    track: async (eventType, payload) => {
        const data = {
            payload,
            location: window.location.href,
            title: document.title,
            pageVars: webcm.pageVars,
            timestamp: new Date().getTime(),
            offset: new Date().getTimezoneOffset(),
            referer: document.referrer,
            eventType,
        };
        const res = await fetch('/webcm/track', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(data),
        });
        return webcm._processServerResponse(res);
    },
    _syncedAttributes: [
        'altKey',
        'clientX',
        'clientY',
        'pageX',
        'pageY',
        'button',
    ],
};
webcm.pageVars.__client.track = true;
webcm.track('pageview');
"use strict";
window.addEventListener('message', ({ data }) => {
    if (data.webcmUpdateHeight)
        document.getElementById(data.id).height = data.h;
}, false);
;webcm._processServerResponse({"pageVars":[],"fetch":[],"execute":[]})</script>
	<title>Holiday Setup</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="theme-color" media="(prefers-color-scheme: light)" content="white">
	<meta name="theme-color" media="(prefers-color-scheme: dark)" content="black">
	<link rel="stylesheet" href="[style.css](http://192.168.1.212:8787/style.css)">
</head>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions