Google Chrome Extension Manifest Version 3 with Paypal Payment Integration

Struggling to integrate a Paypal smart button into my Google Chrome Extension.

The JSFiddle demo shows the working button. Check out the newer version below for updates.

Newest JSFiddle

The page functions properly on localhost as well.

https://i.sstatic.net/J5Sw0.jpg

However, loading the buy page from the chrome extension results in visual and console errors.

https://i.sstatic.net/ZYIoX.jpg

https://i.sstatic.net/NSfBW.png

The script fails to load due to violating the content security policy directive "script-src 'self'".

After testing, adding the meta tag mentioned in the HTML allows it to function without disappearing when run as a file.

<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline' 'unsafe-hashes' fonts.googleapis.com; object-src 'self' https://www.paypal.com 'sha256-U2vsCzUQ797LcHkgCQJsOSAJxY/+LTdJONJ+wacPXrI='; script-src-elem 'self' 'unsafe-inline' https://www.paypal.com">

This solution works because the paypal button was being loaded inline initially. I have now updated the code in this JSFiddle.

Improvements include loading JS and CSS files separately, avoiding unsafe-inline issues with Content Security Policy.

Despite these changes, the error persists when trying to load the buy page via the chrome extension.

Note that the page is created from a button press on the popup page, triggering a message to the background service worker which opens the page. The page appears correct except for missing the paypal button.

if (request.buy != null) {
   chrome.tabs.create({
       url: 'buy.html'
   });
}

How can I resolve the issue of the paypal button not displaying correctly within a Google Chrome extension using manifest 3?

I've tried modifying the manifest with:

"content_security_policy": {
        "extension_pages": "default-src 'self';script-src 'self'"
    }

Unfortunately, this did not work, causing strange display issues on the buy page with elements disappearing.

https://i.sstatic.net/UvCIy.png

Google doesn't support 'unsafe-inline' or 'unsafe-hash', leaving me unsure how to proceed. Any assistance would be greatly appreciated!

Manifest.json details:

{
    "name" : "Trading View Input Optimizer",
    "description" : "Automatically experiment with different inputs to discover which inputs deliver the optimal results with an optional easy to see heat map",
    "version" : "1.0.0",
    "manifest_version": 3,
    "icons": {
        "16": "./images/icon-16.png",
        "32": "./images/icon-32.png",
        "48": "./images/icon-48.png",
        "128": "./images/icon-128.png"
    },
    // More manifest details...
}

Answer â„–1

After running a test, I discovered that adding a specific meta tag to the HTML allows it to work when viewed as a file without any disappearing elements.

Unfortunately, jsfiddle.net does not support custom meta tags. If you inspect the iframe content of your test on jsfiddle, you will see:

<!DOCTYPE html>
<html>
<head>
... jsfiddle's head content ...
</head>
<body>
<body>
  <!DOCTYPE html>
  <html lang="en">
    <head>
    ... your head content with <meta CSP> ...
    </head>
   <body>
   ... content of page ...
</body>
</html>

If the Meta tag Content-Security-Policy is not correctly placed within the <head> section, it will be ignored and not applied as expected.

Manifest V3 does not permit the use of external scripts. Check out this comment regarding a similar issue with Manifest V3 for Facebook SDK script, it may provide some insights.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Boost All Elements of Object Array Simultaneously with Mongoose Increment Method

I'm currently working on a project to track statistics on users (for a discord bot) like command usage and more. My goal is to store all this data in my mongodb. Essentially, I am aiming to regularly update the database with an array that records use ...

Using AngularJS ng-repeat to create tabbed interfaces

In my current scenario, a dynamic number of tabs can be created. When a user clicks on an entry in a commands menu, a new pill-tab pair is added to the existing ones (Note: Bootstrap is used for styling). The list of tabs is managed within an array in $ro ...

Update depth has exceeded the limit, the useEffect in React is causing issues

I encountered a strange error while working with the component below. The error seems to occur only when I make changes to the file, like altering a default prop, and then saving the file. I believe the issue stems from the props triggering a re-render, as ...

Troubleshooting an Issue with MediaStreamRecorder in TypeScript: Dealing with

I've been working on an audio recorder that utilizes the user's PC microphone, and everything seems to be functioning correctly. However, I've encountered an error when attempting to record the audio: audioHandler.ts:45 Uncaught TypeError ...

Setting up a div as a canvas in Three.js: Step-by-step guide

Is there a way to adjust the JavaScript in this three.js canvas example so that the scene can be contained within a specific div element on a webpage? Here is the example: https://codepen.io/PedalsUp/pen/qBqvvzR I would like to use this as the background ...

Control checkbox state based on Grandparent or parent selection in Vue

Currently, I am attempting to toggle a checkbox based on the status of either the grandparent or parent checkboxes: new Vue({ el: '.app', data: { grand_parent: false, parent: false } }) Unfortunately, it is not working as expected ...

Tips for shrinking grommet's webpack bundle size

Hey there! Recently, I started exploring Grommet and worked on my first application by following their step-by-step guide. However, I noticed that the webpack bundle created for production is quite large, exceeding 1.7 MB even though I haven't added a ...

Unravel intricate JSON data and display it in a Material-UI table

How to convert the complex JSON data provided below into a material-ui table similar to the example shown. Each row may contain either a single value or multiple rows in a single box. I have attempted to display the data in 2 columns only, but need help wi ...

Uploading Files with Additional Information in Angular

I am currently utilizing the Angular-file-upload library to upload files to an API. This is how I'm approaching it: var uploadFile = function (file) { return $upload.upload({ url: '/api/place/logo', data: {place_id: 1, t ...

JavaScript makes it easy to streamline conditions

Can someone help me simplify this repetitive condition? if (this.get('fileUrl')) { const isUnsplash = this.get('fileContainer.asset_kind') === 'UnsplashAsset'; return Asset.create({ url: this.get('f ...

Can you use ng-show within ng-if in Angular?

How can I make this input only show a property is true per the ng-if? The current code looks like this: <input type="button" class="naviaBtn naviaBlue" ng-if="ppt.Globals.hasDebitCard" ng-click="alertShow = (alertShow == 2 ? -1 : 2)" value="outstandin ...

Avoid using the 'exports' keyword when compiling in Typescript

I recently started learning Typescript, although I am proficient in JS. My inquiry pertains to utilizing modules in TS for coding purposes and then excluding the modules when converting to JS. In traditional JS, I segment functionalities into different fi ...

When using Laravel and Vue in Javascript, the Array Length function may sometimes return an undefined

I'm currently immersed in a project utilizing Vue + Laravel, where I rely on axios for handling AJAX requests to fetch data from controllers and showcase it on the Javascript side. However, when employing nested for loops, I encounter some peculiar be ...

Stack of Error Messages on jQuery AJAX Form Submission

How can I prevent the display of multiple error messages in my form with required fields? Currently, when attempting to continue without entering anything into the required fields, a new error message is created underneath the previous one. What steps sh ...

Cipher Caesar - symbols and additional characters

I've constructed a Caesar Cipher script down below, however, I wish for the output string to contain spaces and other characters. Despite my attempts with regex, it doesn't seem to rectify the issue or maybe I'm not utilizing it correctly †...

Can you explain the distinction between export/import and provide/inject in Vue3?

Can you explain the difference between export/import and provide/inject in Vue3? // parent const data = provide('data', ref(0)) // child const data = inject('data') // parent export const data = ref(0) // child import { data } from & ...

When the document is fully loaded on a page that has been dynamically loaded

Currently utilizing the following: $("#someDiv").load("ajax.html") The contents of "ajax.html" include a document.ready call: <script>$(function() { alert('works') })</script> I'm interested to know exactly when this callbac ...

A JavaScript or CSS file within an HTML document

I understand this may seem like a silly question. However, out of curiosity, is there a way to upload an HTML file (with a .html extension) as a JavaScript or CSS file (renamed with a .js or .css extension), specifying the type header as either HTML or js ...

What is the best way to show a tooltip alongside highlighted text?

How can I display a tooltip (using qTip) next to selected text? The code below captures the selected text in the console, but the tooltip is not displayed. <div class='test'>Actual text will be much longer...Test Test Test Test Test Test T ...

What is the best way to determine which id has been clicked using jQuery?

Can someone help me figure out how to determine which button has been clicked using jQuery? Here is the HTML code I am working with: <div class="row"> <div class="col-md-6"> <div class="well " id="option_a"> </div& ...