Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/client/console.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Some extra functionality that is made available in the command line console7for debugging and generally working with CoCalc.89For security reasons, only available in DEBUG mode (e.g,. when doing cc-in-cc dev),10not in production.1112Security note: not easily exposing this to the global scope would make it harder13for an attacker who is eval'ing dangerous code in a Sage worksheet (say).14However, even if it were not exposed, the attacker could just do15"conn = new Primus(url, opts)"16and make a Primus connection, and start sending/receiving messages. This would work,17because the primus connection authenticates based on secure https cookies,18which are there. So we could make everything painful and hard to program and19actually get zero security gain.2021**CRITICAL:** If the smc object isn't defined in your Google Chrome console session,22you have to change the context to *top*! See23http://stackoverflow.com/questions/3275816/debugging-iframes-with-chrome-developer-tools/8581276#858127624*/2526declare const DEBUG; // this comes from rspack.27console.log("DEBUG = ", DEBUG);2829import { IS_TOUCH } from "../feature";30import { redux } from "../app-framework";3132declare global {33interface Window {34cocalc: any; // special support for debugging35cc: any; // alias for "cocalc"36eruda: any; // provides a debugger for mobile devices (iOS).37}38}3940export function setup_global_cocalc(client): void {41if (!DEBUG) {42return;43}4445const cocalc: any = window.cc ?? {};46cocalc.client = client;47cocalc.misc = require("@cocalc/util/misc");48cocalc.immutable = require("immutable");49cocalc.done = cocalc.misc.done;50cocalc.sha1 = require("sha1");51cocalc.prom_client = require("../prom-client");52cocalc.schema = require("@cocalc/util/schema");53cocalc.redux = redux;54cocalc.load_eruda = load_eruda;55cocalc.compute = require("@cocalc/frontend/compute/api");56console.log(57"DEBUG: Enabling extra CoCalc library functionality. Type cocalc or cc.[tab].",58);59window.cocalc = window.cc = cocalc;6061if (IS_TOUCH) {62// Debug mode and on a touch device: always load eruda so we63// get a nice dev console! This is very handy for iPad development.64load_eruda();65}66}6768function load_eruda(): void {69// -- e.g., iPad -- so make it possible to get a70// devel console via https://github.com/liriliri/eruda71// This pulls eruda from a CDN.72const script = document.createElement("script");73script.src = "//cdn.jsdelivr.net/npm/eruda";74document.body.appendChild(script);75script.onload = function () {76window.eruda?.init();77};78}798081