Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chrome: konva tab missing #92

Closed
HansKrywalsky opened this issue Jan 6, 2024 · 20 comments
Closed

chrome: konva tab missing #92

HansKrywalsky opened this issue Jan 6, 2024 · 20 comments
Assignees
Labels
bug Something isn't working

Comments

@HansKrywalsky
Copy link

Describe the bug
A clear and concise description of what the bug is.

I'm currently trying to make this inspector work in chrome. I installed the extension, relaunched chrome and start my konva app.

When i press on the extension it says that konva is detected:

Bildschirmfoto 2024-01-06 um 12 41 49

But there is no konva tab in my dev tools:
Bildschirmfoto 2024-01-06 um 12 44 04

Am i missing something?

@HansKrywalsky HansKrywalsky added the bug Something isn't working label Jan 6, 2024
Copy link

github-actions bot commented Jan 6, 2024

Thank you for your contribution. We will check and reply to you as soon as possible.

@maitrungduc1410
Copy link
Owner

maitrungduc1410 commented Jan 7, 2024

you should try close the browser dev tool and reopen again.

if it still doesn't work, please provide a working example using Codesandbox or similar platforms.

Quick links to test konva-inspector:

Screenshot 2024-01-07 at 3 32 56 PM

@HansKrywalsky
Copy link
Author

Hey @maitrungduc1410 - I'm using Konva 9.3.0

All the links you provided work for me. Re-openeing the dev tools does not in my application.

Is the problem maybe that the konva is not on the first screen? You have to navigate into the page where it appears first

@maitrungduc1410
Copy link
Owner

maitrungduc1410 commented Jan 7, 2024

there's an interval runs every 1 second:

const detectFromDevtoolInterval = setInterval(detectFromDevtool, 1000);

it'll check if Konva is detected on current browser window and show Konva tab in your browser devtool.

what I recommend is: when you know Konva is actually on a page, then open (or reopen) the browser devtool (I do this for other extensions also: React, Vue,...)

In your case: konva is not in first screen, then in second screen where you know it actually is -> open browser devtool

@HansKrywalsky
Copy link
Author

Doesn't work for me 😕

@maitrungduc1410
Copy link
Owner

In your case , is it like:

  • first page: no konva
  • redirect to page 2: have konva

And it's SPA right? React?

@HansKrywalsky
Copy link
Author

Specificly it is an Ionic + Angular application.

I open a modal which is a to the dom attached element. Inside this element i navigate to another internal page, there is the konva

@maitrungduc1410
Copy link
Owner

Is it in iframe?

@HansKrywalsky
Copy link
Author

No

@maitrungduc1410
Copy link
Owner

maitrungduc1410 commented Jan 7, 2024

Oh, it's webcomponent right?

In this case it has its own DOM (shadowDOM) it's very hard (but possible) for my dev tool to know if Konva is presented inside your component (since you can create any web component, div/span/.... also web component)

@HansKrywalsky
Copy link
Author

The Ionic components use shadow dom, yes but my component should be in the light dom anyways 🤔

I will try to prepare a small reproducion in the next days when i found the time, when this is okay for you. Then we can check if the shadow dom is the problem

@maitrungduc1410
Copy link
Owner

Yeah, it'll be much easier for me to debug if you can provide reproducible example :)

@EinfachHans
Copy link

Hey @maitrungduc1410 - just switched to my main account^^

i created a reproducible repo here: https://github.com/EinfachHans/ionic-konva-inspector-bug

You can start it with npm run start, i added two konva's: one in the home page, which is the first page you are automatically routed to and one inside the modal you can open from there. For me: Both are not detected from the inspector. Tested in google chrome

@maitrungduc1410
Copy link
Owner

I'll check and get back to you

@maitrungduc1410
Copy link
Owner

Hi @EinfachHans, I checked your example

In both cases Konva stage is rendered inside ShadowDOM:
Screenshot 2024-01-09 at 10 12 09 AM

Screenshot 2024-01-09 at 10 13 35 AM

@maitrungduc1410
Copy link
Owner

maitrungduc1410 commented Jan 9, 2024

I tried with no ShadowDOM, and still doesn't work:

Screenshot 2024-01-09 at 10 17 29 AM

I figured out that, in your global Konva object, it's very limited, has just few props, and one thing important is it doesn't have stages property. That why my dev tool can't figure out, as described here

Screenshot 2024-01-09 at 10 20 35 AM

@maitrungduc1410
Copy link
Owner

Found it,

You need to use this way:

import Konva from 'konva'

new Konva.Stage(...)
new Konva.Layer(...)

This usage also same as in Konva official docs.

it works now:

Screenshot 2024-01-09 at 10 34 34 AM

@maitrungduc1410
Copy link
Owner

1 thing I need to correct after review my code, my dev tools works regardless of whether it's ShadowDOM or not, it works universally.

My explanation yesterday was incorrect :)

@maitrungduc1410
Copy link
Owner

maitrungduc1410 commented Jan 9, 2024

In case you don't want to change the import styles then you can do this:

import { stages } from 'konva/lib/Stage';
import { Util } from 'konva/lib/Util';

// do this once before you initialize your Stage, from anywhere in your app
(window as any).Konva.stages = stages;
(window as any).Konva.Util = Util;

Then you can keep your code as it is, no change:

import { Stage } from 'konva/lib/Stage';
import { Layer } from 'konva/lib/Layer';
import { Circle } from 'konva/lib/shapes/Circle';

const stage = new Stage({
  container: 'container-home',
  width: 300,
  height: 300,
});

const layer = new Layer();
stage.add(layer);

const circle = new Circle({
  x: 150,
  y: 150,
  width: 300,
  height: 300,
  fill: 'blue',
});

@EinfachHans
Copy link

Thank you for your dive-in, i made it work with this! Thanks a lot, you made an awesome tool! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants