kamranahmedse / driver.js

A light-weight, no-dependency, vanilla JavaScript engine to drive the user's focus across the page

Home Page:https://driverjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Skip step for missing element

lonix1 opened this issue · comments

(This is a question rather than bug report, as the repo doesn't have a "discussions" tab.)

New user here. I'm using the CDN script, on a server-rendered app.

Suppose my page does not contains some element. When that step is reached, a popup is shown in the middle of the screen, with the relevant text and buttons.

I'd like to skip that step.

I know of the "async actions" feature, but it doesn't apply here - I don't want to wait for that element to be created, rather, I want to skip that step.

Is that possible?

Just saw this in another issue (#484). Filter steps that have valid selectors. But this doesn't account for elements that get removed over time as this would be done on initialization of the tour...

const filteredSteps: any = steps.filter(step => {
  const element = document.querySelector(step.element)
  return !step.element || element !== null
})

You could probably also check the onNextClick()/... handlers to check if the next/... N steps are possible otherwise skip them.

commented

Those are good workarounds to avoid the problem.

The best solution though is to have a built-in mechanism for this... something like "if selector is invalid, skip step". And configurable by an option of course.