Giter VIP home page Giter VIP logo

penpot-devtools's Introduction

Penpot DevTools

What you can do

  1. Use a ClojureScript REPL with direct access to app's current state.

  1. Inspect current state (with specific type info).

  1. Enable/Disable debug options.

Known issues

  1. Sometimes the DevTools panel gets disconnected from the main context (you can Reload frame inside DevTools to fix this).

Initialization

  1. Everytime we open DevTools in the specified URLs ([http://localhost:3449] or [https://design.penpot.dev]), the devtools.html is loaded, then devtools.js is loaded through the script tag.

  2. devtools.js injects the content-scripts/isolated.js in an Isolated Context (like an IFrame) in the target website, then this isolated.js connects to the devtools through chrome.runtime.connect

  3. When devtools.js receives the connection, injects content-scripts/main.js, this script shares the same context as the Penpot App, so anything we execute in this context can access any of the exposed javascript APIs of the Penpot App.

sequenceDiagram
  DevTools ->> Isolated Context: chrome.scripting.executeScript
  Isolated Context ->> DevTools: chrome.runtime.connect
  DevTools ->> DevTools Panel: chrome.devtools.panels.create
  DevTools ->> Main Context: chrome.scripting.executeScript
  Main Context ->> Isolated Context: window.postMessage

Permissions

This extension is limited to [http://localhost:3449] and [https://design.penpot.dev], any other URL will be excluded. Permissions should be the minimal to retrieve and send useful information to Penpot.

Messaging

A message needs to be resend multiple times because of the browser isolated contexts.

sequenceDiagram
  Main Context ->> Isolated Context: window.postMessage
  Isolated Context ->> DevTools: port.postMessage
  DevTools ->> DevTools Panel: window.postMessage
  DevTools Panel ->> DevTools: window.postMessage
  DevTools ->> Isolated Context: port.postMessage
  Isolated Context ->> Main Context: window.postMessage

REPL

To implement the ClojureScript REPL we use a globally exposed function called cljs_eval. This function runs asynchronously and returns the result of the evaluated expression.

Development

Load unpacked extension

Go to [chrome://extensions] and click on Load unpacked, then select the folder of this repository (where this README.md is located) and click OK. If everything went ok, you should be able to see this extension in the list of installed extensions.

Rebuild and refresh

If you modify a content-script or one of the main extension files: devtools.html, devtools.js, you only need to refresh the Extension by going to: [chrome://extensions] and clicking into the refresh button of the extension or on the Update button.

Build

When you modify something related to the panel UI (anything inside the src folder), you need to rebuild the project and refresh (as explained in the previous entry).

corepack enable pnpm
pnpm install
pnpm build

If you need to debug the UI you can use pnpm build:dev to build it in development mode.

penpot-devtools's People

Contributors

azazeln28 avatar

Stargazers

Dee Cheung avatar

Watchers

 avatar Andrey Antukh avatar elhombretecla avatar Alejandro avatar Pablo Ruiz Múzquiz avatar Alonso Torres avatar  avatar Eva Marco avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.