Giter VIP home page Giter VIP logo

browser-sdk's Introduction

Official Marker.io browser SDK 🚀

NPM version Download

Website   •   Docs   •   Blog


Table of Contents

Examples

Features

  • Inject Marker.io widget in your web app
  • Full control of the widget (hide / show, trigger captures, ...)
  • Identify reporters (Learn more)
  • Inject custom metadata in issues (Learn more)
  • Silent mode (Learn more)
  • Delayed server-side capture (Learn more)
  • Disabling keyboard shortcuts (Learn more)

Installation

  1. First install the package from npm:

npm install -s @marker.io/browser

  1. Setup the SDK in your code:
import markerSDK from '@marker.io/browser';

const widget = await markerSDK.loadWidget({ project: 'abcd1234567890' });

⚙️ API

widget.show()

Shows the Marker.io feedback widget.

widget.hide()

Hides the Marker.io feedback widget.

widget.isVisible()

Returns wether the feedback widget is currently visible or not.

widget.capture(mode)

Captures a feedback on the current page.

  • mode: Type of capture to trigger. Available modes: fullscreen, advanced.

    • fullscreen captures the entire visible area
    • advanced shows the advanced capture options: limited area, entire page and desktop.
Example
widget.capture(); // or
widget.capture('fullscreen');
widget.capture('advanced');

widget.cancelCapture()

Cancels current capture.

widget.isExtensionInstalled()

Returns a Promise<Boolean> that indicates if the Marker.io extension has been detected. Having the extension installed allows more accurate screen captures and provides more capture options.

Example
widget.isExtensionInstalled().then((installed) => {
  if (installed) {
    // ...
  } else {
    // show install Marker.io extension button
  }
});

widget.setReporter(reporterInfo)

Sets the current reporter information given a reporterInfo object:

  • reporterInfo.email: the email address of the reporter
  • reporterInfo.fullName: the full name of the reporter
Example
widget.setReporter({
  email: '[email protected]',
  fullName: 'Gabrielle Rose',
});

widget.unload()

Unloads and cleans up Marker.io SDK and all used resources.

🚨 Events

Marker.io exposes a variety of events that can be listened to using the methods described below.

Usage:

widget.on('eventName', function listener() {
  // event handler code
});

'load'

Triggers once Marker.io is loaded.

'loaderror'

Triggers if an error occurs while loading Marker.io.

'beforeunload'

Triggers right before Marker.io unloads.

'show'

Triggers when the feedback button becomes visible.

'hide'

Triggers when the feedback button becomes hidden.

'capture'

Triggers when a feedback is captured.

'feedbackbeforesend'

Triggers before submitting the feedback, i.e. when the user clicks Submit feedback.

'feedbacksent'

Triggers once the feedback is successfully submitted.

'feedbackerror'

Triggers if an error occurs while submitting feedback.

'feedbackdiscarded'

Triggers when the user discards a feedback by clicking on the "Close" button in the widget.

🙋‍♂️ Identify reporters

Whenever your application knows about your reporters' identity, you should provide that information through the Marker.io snippet code.

Why?

The reporting experience will be much better for your guests as they will not be prompted to provide their contact information while reporting their issues.

Method 1: passing reporter info while loading your widget

Identifying your reporters is dead-simple: all you need to do is to provide their reporter information in the configuration object of your snippet code.

const widget = await markerSDK.loadWidget({
  project: '<PROJECT ID>',

  reporter: {
    email: '[email protected]',
    fullName: 'John Smith',
  },
});

Method 2: set reporter info using widget.setReporter()

widget.setReporter({
  email: '[email protected]',
  fullName: 'John Smith',
});

⚙️ Custom metadata

While Marker.io automatically captures various metadata about the issue (page URL, browser context, console logs, …), it is also possible to pass custom metadata to your issues using the SDK.

For example, this can be useful to help developers debug issues by adding more details about the current state of the application.

Supported types of custom metadata:

  • number
  • boolean
  • strings
  • arrays
  • objects

Method 1: passing custom metadata while loading your widget

const widget = await markerSDK.loadWidget({
  project: '<PROJECT ID>',

  customData: {
    storeId: 123,
    storeName: 'Organic Fruits',
  },
});

Method 2: set custom metadata using widget.setCustomData()

widget.setCustomData({
  product: 'Orange Juice',
  price: 3.99,
  stock: 130,
});

👻 Enabling Marker.io silent mode

By default, Marker.io will log some useful information in the console to help you identify configuration problems and better understand how it functions.

However, in certain situations you may want to disable them all together so that it doesn't add noise to your recorded console logs.

To do so, you will need to enable silent mode directly inside your snippet code configuration:

const widget = await markerSDK.loadWidget({
  project: '<PROJECT ID>',

  silent: true, // <~ Enable silent mode
});

🕒 Delayed capture using server-side capture

Delay the server-side capture so that your CSS animations can run before the screenshot is taken.

You can enable delayed capture adding a special parameter in your snippet code configuration:

const widget = await markerSDK.loadWidget({
  project: '<PROJECT ID>',

  // Add the following to delay the server-side rendering
  ssr: {
    renderDelay: 3000, // 0 - 15000 (ms)
  },
});

⌨️ Disabling keyboard shortcuts

In some particular cases, our keyboard shortcuts may conflict with your web app, you can easily disable all our shortcuts by passing a specific property in the JavaScript snippet configuration:

const widget = await markerSDK.loadWidget({
  project: '<PROJECT ID>',

  // Toggles off all keyboard shortcuts
  keyboardShortcuts: false,
});

Support

Need help integrating Marker.io with your web app? Feel free to contact us via your Marker.io account.

For every bugs, improvements or feature requests related to this SDK, please report a GitHub issue.

License

Released under the MIT license.

browser-sdk's People

Contributors

ejirocodes avatar emilevictorportenart avatar olivierkaisin avatar olivierkaisin-dev avatar tremby avatar yuripetusko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

browser-sdk's Issues

Add missing options

Some options are missing in the SDK.
May you add them @emilevictorportenart?

(Marker.io SDK) unknown param "silent" (need to upgrade?)
(Marker.io SDK) unknown param "source" (need to upgrade?)
(Marker.io SDK) unknown param "ssr" (need to upgrade?)

Unexpected token 'export' error when loading npm package in React project

When loading the package from a Remix/React project, I'm running into this error:
.../node_modules/@marker.io/browser/src/index.js:5

export default {
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1033:15)
    at Module._compile (node:internal/modules/cjs/loader:1069:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (.../app/root.tsx:12:23)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at .../node_modules/@remix-run/serve/dist/index.js:43:17

Looks like it's trying to load your esm package with the commonjs loader (node:internal/modules/cjs/loader), which leads to an error.
A potential fix for this issue would be to add "type": "module", to the package.json so Node knows that it's an ESM package.

Add domain for analytics to resolve conflicts with CSP policies

It looks like analytics are being loaded from https://s3.eu-west-1.amazonaws.com/marker.sessions.prod. This results in a lot of failed connections in our app because our CSP needs to allow specific domains. Opening it up to all of https://s3.eu-west-1.amazonaws.com would present a security issue that CSP is designed to prevent.

Could you please provide a way for us to resolve this either by using a designated domain for collecting analytics information or something in the SDK to better handle the errors?

Provide CommonJS module export

Currently it breaks with NextJS.

Since NextJS is prerendered serverside, and it uses Nodejs which uses commonjs exports instead, the export default breaks it (expects module.exports = foo)

To fix this, maybe it could be compiled into separate files or into UMD (Universal module definition) by something like rollup

Show us how to disable the console.log interception

I know why this feature exists, but I need to use marker in dev mode and I can't have it interfering with me being able to determine where the log call came from in console dev tools. #20 explains why, but never told us how it can be disabled. How can we disable the console.log interception in marker?

Issue with iframe disappearance and marker.io SDK incompatibility when changing language in Next.js 13 with App routing

Issue Description:
I am currently working on a web project that utilizes Next.js 13 with App routing. To enhance the user experience, I have integrated the react-i18next library for language translation. However, I have encountered a critical issue related to iframe behavior and the functionality of the marker.io SDK when changing the language.

Problem Details:
When I switch the language, the iframe generated by marker.io mysteriously disappears from the page. Upon investigating the issue further, I noticed the following problematic behaviors:

isvisible Function: The isvisible function returns true even though the iframe is no longer visible on the page.

isExtensionInstalled Function: The isExtensionInstalled function returns false, indicating that the marker.io extension is not installed, even though it was working previously.

Error on Reload: If I attempt to reload the page after changing the language, I encounter an error related to the document.querySelector('[data-marker-styles="1"]').remove() operation. This error is specifically a "TypeError: Cannot read properties of null (reading 'remove')".

Context and Workaround:
I have noticed that when I refresh the entire page, the iframe reappears, and everything functions as expected. To provide additional context, I am utilizing the script installer for marker.io because directly importing the SDK from npm leads to a ".remove" error, likely due to its placement within a useEffect function. Unfortunately, changing the language disrupts the entire application and leads to this issue.

Request for Assistance:
I kindly request assistance in resolving this issue. It is critical for the proper functioning of our multilingual web project. Any guidance, insights, or potential workarounds would be greatly appreciated.

Thank you in advance for your help and support in resolving this matter.

Type error with setCustomData

Version 0.16.0

The error is : TS2339: Property 'setCustomData' does not exist on type 'MarkerSdk'.

Code sample below:

const widget = await markerSDK.loadWidget({
    project: 'xxxxxxxxxxxxxxxxxxxx',
  });
  widget.setCustomData({
    userName,
  });

`renderDelay` typescript types are wrong

Docs mention renderDelay value as a number, which is correct, however typescript types for ssr are wrong

ssr?: Record<string, string>;

which results in the following TS error

image

Script error

version: "@marker.io/browser": "^0.19.0"

Following Error logs been found in console
Screenshot 2023-09-29 at 11 39 04 PM

Screenshot 2023-09-29 at 11 39 17 PM

silent mode is not supported

Looking at the doc and see silent mode property in config option while initialisation, but can't find this in source files of the npm package and it throws a warning in console

Disable screenshots

Hi! Im looking for a way to disable automatic screenshots - can this be done somehow via the sdk? Been looking through the documentation but cannot find any info. The reason for this is GDPR - I dont want people to accidently submit personal data due to automatic screenshots.

Devtools Console only shows `shim.js`

I'm currently using redwood.js with marker.io. If marker-io loads in any form, all messages in the Devtools console show up with their source as /shim.js. Any ideas how I can stop this behavior?

image

cannot install the package

When i try to install the package by npm install -s @marker.io/browser i get this error

The splatting operator '@' cannot be used to reference variables in an expression. '@marker' can be used only as an argument to a command. To reference variables in an expression use '$marker'.

perhaps there is an alias that we can use to install the package without using "@"?

any help appreciated
`

Does this library load two versions of marker-io?

While working on performance enhancements in a project, I noticed this library loads two files which seem to be different versions of marker-io or are these file two different things?

/latest/3.v1.49.0.c7628fa0355869e73f1c.js
/latest/4.v1.49.0.cf91bfe42d212993d552.js

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'id')

Just trying to use Marker and the API and I got this error. It shows up on page load intermittently suggesting its possibly some kind of async race condition.

image
image

I'm tracking this back to when I try to call setReporter and I think that I am calling setReporter in my state manager before the Marker Widget is ready for me to call it. Yet, the error is getting emitted for Marker's code so the fix should be on your end.

As for writing code to check if setReporter is safe for me to call; I don't want to, and shouldn't have to wrap a call to setReporter in an marker's on event handler method because that is not an acceptable workaround for bunch of reasons that I don't want to get into.

Thank you!

META: The SDK needs some attention

This SDK is basically a vehicle for marker to inject their widget script from a remote host (outside of the control of the customer) into a client application. Because of this, it's impossible to independently audit, or manage the release version, or gain helpful insights into the SDK being used.

I think that the current approach is holding marker.io back because as I dig more and more into how it works, the more uncomfortable I become about using it. Marker's SDK is no different from adding a script via CDN, except that script is a black-box and we have no control over the script's version, contents, etc. Marker could push an update that breaks our software and there would be no way to stop it with any QA processes. This needs to change.

With that said, I hope to see improvements to Marker soon!

  • #26 is almost 1 yo.
  • Or what about this one? #35
  • And have you considered that because loadWidget is an async function that you're making things hard for us developers to figure out when we're able to actually make calls to the API from the window global? I have a dev toolbar and if it loads in before your widget has initialized, I can't get the marker widget state or manipulate it's behaviors appropriately.

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.