BUG: page.getMainComponent().view gives undefined when page is selected
Question
Hello @artf, I want to get the HTML Element of selected page. But it returns undefined when using following code:
editor.on('page:select', page => {
page.getMainComponent().view.el.querySelector('section'); // There is section tag inside that page...
});
Answers (2)
Hi @iabhiyaan, when page:select triggers, iframes inside the canvas are not yet loaded, so you just need to wait once they are loaded before accessing its DOM.
editor.on('page:select', page => {
const frame = page.getMainFrame();
frame.once('loaded', () => {
const rootEl = frame.getComponent().getEl();
console.log(rootEl.querySelector('section'));
});
});
Thankyou @artf.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2029
[Question/Bug] grapesjs throws a DOMException if you import HTML contents with invalid (numbered) attributes
Hi @artf , We got a report that when you import some HTML code with incorrect attributes, such as <td class="cell" 01234="0" >Hello world!...
Issue #1128
Bug in dragging selected text
hi @artf as you can see my screenshot when you drag textblock than select text in that element and drag it to bottom of content than text g...
Issue #2953
BUG: Error when navigating out from Grapes with something selected.
Hey @artf, Steps: Open Canvas with GrapesJS, select any of the components, then click on Go to Random, I get an error that says "Cannot rea...
Issue #2661
[BUG] toggleStateCls returns js error
Hi there, guys. I found a bug at the LayerManager: I've got an html comment as a layer in the LM. I click the comment. I get an error at th...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.