Creating a content security policy for embedded Google Maps iframe - javascript

I've created a React component for an embedded Google Maps iframe which works as intended. However, the browser console repeatedly warns me about the content security policy:
I went looking for solutions, but I only found answers related to the API. The concepts of content security policy and manifest.json is new to me and something I'll look into moving forwards, but for now I only need help setting up the manifest.
Manifest
"permissions": [
"https://www.google.com/maps/*"
],
"content_security_policy": ""
Component
import React from "react";
export default function GoogleMap(props: {
title: string,
src: string,
width?: string,
height?: string
}) {
return (
<iframe
title={ props.title }
src={ props.src }
width={ props.width || "100%"}
height={ props.height || "450"}
loading="lazy"
></iframe>
)
}
Component call
import React from 'react';
import './App.css';
import Jumbotron from './components/Jumbotron';
import GoogleMap from './components/GoogleMap';
function App() {
return (
<div className="container">
<div className="row">
<div className="col">
<Jumbotron>
<h1>Hello World!</h1>
<p>Something, something</p>
</Jumbotron>
</div>
</div>
<div className="row">
<div className="col">
<GoogleMap
title="Map of Mobit Stakkevollvegen"
src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d490.15681762061814!2d18.969382885920925!3d69.66688347864422!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x45c4c45ca1720dbb%3A0x48debf799412e7a8!2sMobit%20Stakkevollvegen!5e0!3m2!1sno!2sno!4v1624610965243!5m2!1sno!2sno"
/>
</div>
</div>
</div>
);
}
export default App;
What do I put into the manifest.json in order to remove the browser console warnings in a secure manner?

I am not sure if these warnings are exclusive to Firefox, but this reddit post seems to say that these warnings are caused by something on Google's end. Therefore, although you should implement a CSP to secure your app, I do not think doing so will remove the warnings.

Related

localhost server not displaying image (React)

I am learning react and following a series of challenges to do so. One such challenge has me create a React component that takes in properties. One of these properties is the name of a png file. I was not able to do this correctly but the correct line does not seem to be working.
This is an Ubuntu distro on WSL on a windows laptop.
I have done research on the topic the last few days and most response say to turn off adblocker (did not fix it), change file permissions (also did not work), turn off JS and CSS source maps (also did not work).
I noticed that a manually coded url to an image in the same folder was changed to
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgA…Cxd82/eqNyzDUJ0ohc8k/PbelTLtHJFgAAAAASUVORK5CYII=
My component is
import React from "react";
import star from "../images/star.png";
export default function Card(props) {
return (
<div className="card">
<div className="card--image">
<h3 className="card--availability">SOLD OUT</h3>
<img src={`../images/${props.img}`} alt="not working"></img>
</div>
<div className="card--rating">
<img src={star}></img>
<p className="card--dark-text">{props.rating}</p>
<p className="card--light-text">
({props.reviewCount}) · {props.country}
</p>
</div>
<p className="card--desc">{props.title}</p>
<div className="card--price">
<h5>From ${props.price}</h5>
</div>
</div>
);
}
Which is used in
import React from "react";
import Navbar from "./components/navbar";
import Hero from "./components/hero";
import Card from "./components/card";
export default function App() {
return (
//<Hero />
<div>
<Navbar />
<Card
img="zeferes.png"
rating="5.0"
reviewCount={6}
country="USA"
title="Playing on the beach with me."
price={136}
/>
</div>
);
}
My file directory looks like
And every other property works.
The displayed screen right now is:
What is going wrong?
Thank you for any help.
import for the image file(zeferes.png) is missing in Card component.
importing image file in Card component should fix the issue.

How to show a specific image from a group as the one in focus

Greetings fellow nerds,
Hope you had a great thanksgiving. I have been working on my portfolio website lately and have almost completed it. Luckily this time I saved the best problem for last, but I haven't had any luck hacking it.. so hopefully one of you has a helpful answer.
So here's the problem:
I have a slider on my front page which at the moment shows the slider starting from the top of the 1st image. Which makes sense of course. But what if I would wish to have it start in focus on the 2nd image?
I tried something with the index without any luck. But here's two pictures that can hopefully help explain the problem:
Bad:
Good:
Scroll container code:
import React from "react";
import { ProjectData } from "../projects/ProjectData";
import ProjectImage from "./ProjectImage";
import ScrollContainer from "react-indiana-drag-scroll";
import "./scss/ProjectCarousel.scss";
export default function ProjectCarousel() {
return (
<ScrollContainer className="scroll-container">
{ProjectData.map(({ id, ...otherProps }) => (
<ProjectImage key={id} {...otherProps} />
))}
</ScrollContainer>
);
}
Project image component code:
import React from "react";
import GitIcon from "../soMe/icons/github_legend.png";
import "./scss/Project.scss";
export default function ProjectImage({ imageUrl, alt, github,
webUrl }) {
return (
<div className="image">
<a href={webUrl} alt="Go to this project's website">
<img src={imageUrl} alt={alt} />
<a href={github} alt="See project on Github">
<div className="overlay">
<img src={GitIcon} alt={alt} />
</div>
</a>
</a>
</div>
);
}
Appreciate any hints or solutions
The images required a fixed height to be rendered and picked up by the scrollto

Browser does not render images in React App

Images not rendered when I use Brave browser but when I use other browsers i.e. Chrome, the images in my app are rendered.
as you can see in my code I created an object that handles all the images so that I can dynamically import those images in my components.
const Assets = {
logo: require('./logo.svg').default,
spots: require('./spots.svg').default,
};
export default Assets;
here is the component that imports some of those images:
import Assets from '../Assets/Index.js'
export default function ButtonAppBar() {
const classes = useStyles();
return (
<div className={classes.root}>
<AppBar position="fixed">
<Toolbar variant='regular'>
<Button className='button-image__logo' variant="text">
<img src={Assets.logo} alt="logo" />
</Button>
<Button className='button-image__spot' >
<img src={Assets.spots} alt="car-spot" />
</Button>
<Button variant="text" color="primary" size='large'>Login</Button>
</Toolbar>
</AppBar>
</div>
);
}
other stack overflow solutions say that I should reinstall webpack, this I have done but the problem still persists.
I have also tried clearing Brave's Cache, it does not change anything.
Is it a problem with Brave Browser or React itself and what can I do to fix this?
NB: I used yarn create react-app

React error: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node

I am trying to map the response I get from an api call. I want to render a div in this map. This is what my code looks like:
<div data-simplebar className="img-scroll">
{this.state.imageSearchResults.items.map((item, ind) => {
return <div className="image-square" style={{backgroundImage:`url(${this.state.imageSearchResults.items[0].link})`}}></div>
})}
</div>
I am getting an error saying
Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
What is wrong with this? I have done mapping in same way in the past and never got such an error.
Wrapping up the translatable text within <p> or <span> sorted out issue for me
Looking at this <div data-simplebar className="img-scroll"> in your question, it looks like you are using the 'simplebar' plugin, which changes the DOM tree and breaks React.
Try to use the package for React 'simplebar-react' instead, it works correctly.
React example:
import React, { Component } from 'react';
import SimpleBar from 'simplebar-react';
import 'simplebar/dist/simplebar.min.css';
import logo from './logo.svg';
import './App.css';
class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<SimpleBar style={{ height: '300px' }}>
{[...Array(50)].map((x, i) =>
<p key={i} className="odd">Some content</p>
)}
</SimpleBar>
</div>
);
}
}
export default App;
If anyone stumbles upon this problem while a page is being translated in Google Chrome, it's likely it has something to do with this:
https://github.com/facebook/react/issues/11538
It's an old issue that's yet to be solved by the Chrome team:
https://bugs.chromium.org/p/chromium/issues/detail?id=872770
Please add a reasonable key prop to the children.

Calling different components into rows in React

I have a very basic question that I cannot comprehend and need some help. I'm creating a really small React project for my personal website. I have App.js that is calling all the different components such as header, intro and etc:
import React from 'react';
import Header from './Header';
import Intro from './Intro';
export default class App extends React.Component {
render() {
return (
<div className="container">
<div className="row">
<div className="col-xs-6">
<Header />
</div>
</div>
<div className="row">
<div className="col-xs-6">
<Intro />
</div>
</div>
</div>
)
}
}
As you can assume, header is just the top portion of the page and intro (currently) just says some text. This is what it looks like:
The second component is being blocked by the first component. Can someone explain how React works with components in terms of how it's rendered on the web page? Or is this purely a HTML issue in App.js?

Categories