Git Product home page Git Product logo

d2n's Introduction

Hi there 👋, I'm Henry, a frontend developer

  • 🛠 I'm developing stuff with JavaScript/TypeScript, Node.js, Vue, Tailwind
  • 🧠 I'm using Dendron for Personal knowledge management
  • 👨🏻‍💻 Most of my projects are available on Github.
  • 📫 How to reach me: [email protected]

d2n's People

Contributors

henryc-3 avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

d2n's Issues

TypeError: Cannot read properties of undefined (reading 'sendMessage')

Description

When using chrome.runtime.sendMessage in vue-router guard router.forEach it throws TypeError: Cannot read properties of undefined (reading 'sendMessage') and <router-view/> renders noting.

image

Example

  • router.ts
router.beforeEach(() => {
	sendToBackground(
		{ checkAuthInfoExist: true },
		{
			successAction: () => {
				return true;
			},
			failedAction: () => {
				router.push("/auth");
			},
		}
	);
});
  • sendToBackground.ts
import { BackgroundResponse, OneTimeMessage } from "../../types";

type SuccessAction = (input: NonNullable<BackgroundResponse["data"]>) => void;
type FailedAction = (input: NonNullable<BackgroundResponse["error"]>) => void;

export function sendToBackground(
	input: OneTimeMessage,
	actions: { successAction?: SuccessAction; failedAction?: FailedAction } = {}
) {
	chrome.runtime.sendMessage<OneTimeMessage, BackgroundResponse>(
		input,
		(res) => {
			if (res.data && actions.successAction) {
				actions.successAction(res.data);
			}
			if (res.error && actions.failedAction) {
				const err = res.error;
				actions.failedAction(err);
			}
		}
	);
}

Related Commit

e850aa5

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.